2017-03-23 20:39:33 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
class NamedChunksPlugin {
|
|
|
|
|
|
|
|
static defaultNameResolver(chunk) {
|
|
|
|
return chunk.name || null;
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(nameResolver) {
|
|
|
|
this.nameResolver = nameResolver || NamedChunksPlugin.defaultNameResolver;
|
|
|
|
}
|
|
|
|
|
|
|
|
apply(compiler) {
|
2017-12-06 22:01:25 +08:00
|
|
|
compiler.hooks.compilation.tap("NamedChunksPlugin", (compilation) => {
|
|
|
|
compilation.hooks.beforeChunkIds.tap("NamedChunksPlugin", (chunks) => {
|
2018-01-22 20:52:43 +08:00
|
|
|
for(const chunk of chunks) {
|
2017-03-23 20:39:33 +08:00
|
|
|
if(chunk.id === null) {
|
|
|
|
chunk.id = this.nameResolver(chunk);
|
|
|
|
}
|
2018-01-22 20:52:43 +08:00
|
|
|
}
|
2017-03-23 20:39:33 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = NamedChunksPlugin;
|