@ali-i18n-fe/dada-component
Version:
20 lines (17 loc) • 609 B
JavaScript
class LibraryNameReplacePlugin {
constructor(options = {}) {
this.replacer = options.replacer || ((path, chunk) => path);
}
apply(compiler) {
const entries = Object.keys(compiler.options.entry);
compiler.hooks.compilation.tap("TemplatedPathPlugin", compilation => {
const mainTemplate = compilation.mainTemplate;
mainTemplate.hooks.assetPath.tap("TemplatedPathPlugin", (path, data) => {
if (data.chunk && entries.includes(data.chunk.name)) {
return this.replacer(path, data.chunk);
}
});
});
}
}
module.exports = LibraryNameReplacePlugin;