Skip to content

Instantly share code, notes, and snippets.

@alexnoz
Created July 17, 2018 17:47
Show Gist options
  • Save alexnoz/f39671163a25762165817cefff7b2077 to your computer and use it in GitHub Desktop.
Save alexnoz/f39671163a25762165817cefff7b2077 to your computer and use it in GitHub Desktop.
A webpack plugin for renaming individual chunks
const id = 'RenameChunkPlugin'
module.exports = class RenameChunkPlugin {
constructor (filenameMap) {
this.filenameMap = filenameMap
}
apply (compiler) {
compiler.hooks.thisCompilation.tap(id, compilation => {
compilation.hooks.optimizeChunkModules.tap(id, chunks => {
const { filenameMap } = this
chunks.forEach(chunk => {
const fname = Object.keys(filenameMap)
.find(fname => fname === chunk.name)
if (fname)
chunk.filenameTemplate = filenameMap[fname]
})
})
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment