webpack/lib/NamedChunksPlugin.js

31 lines
660 B
JavaScript
Raw Normal View History

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