Skip to content

Instantly share code, notes, and snippets.

@jbellenger
Last active July 21, 2017 15:36
Show Gist options
  • Save jbellenger/4565269723ef569cd1a4300e7b322545 to your computer and use it in GitHub Desktop.
Save jbellenger/4565269723ef569cd1a4300e7b322545 to your computer and use it in GitHub Desktop.
named chunks
// All webpack chunks have an identifier that is written to both the chunk and
// the chunk manifest.
//
// By default, webpack uses "int" identifiers, where the identifiers are
// sequentially generated after chunks are ordered by OccurenceOrderPlugin.
//
// The result of this is that small code changes may cause chunks to be
// reordered, leading to a cascading change of chunk ids, and a large number of
// chunk rehashes that could have been avoided.
//
// This plugin assigns chunk identifers based on the chunk name, which should
// be both unique and stable, and reduce the number of chunk rehashes.
class NamedChunksPlugin {
apply(compiler) {
compiler.plugin('compilation', (compilation) => {
compilation.plugin('before-chunk-ids', (chunks) => {
chunks.forEach((chunk) => {
chunk.id = chunk.name;
});
});
});
}
}
module.exports = NamedChunksPlugin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment