/
index.js
44 lines (41 loc) · 1.28 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class ChunksRenamePlugin {
constructor(chunksToRename = {}) {
Object.keys(chunksToRename).forEach(key => {
this[key] = chunksToRename[key];
});
}
apply(compiler) {
compiler.hooks.compilation.tap(
"ChunksRenamePlugin",
(compilation, { normalModuleFactory }) => {
compilation.chunkTemplate.hooks.renderManifest.tap(
"ChunksRenamePlugin",
(result, options) => {
const chunk = options.chunk;
const outputOptions = options.outputOptions;
if (
this.initialChunksWithEntry &&
chunk.hasEntryModule() &&
chunk.isOnlyInitial()
) {
chunk.filenameTemplate =
typeof this.initialChunksWithEntry === "boolean"
? outputOptions.filename
: this.initialChunksWithEntry;
}
if (this.asyncChunks && !chunk.isOnlyInitial()) {
chunk.filenameTemplate = this.asyncChunks;
}
if (
this.hasOwnProperty(chunk.name) &&
typeof this[chunk.name] === "string"
) {
chunk.filenameTemplate = this[chunk.name];
}
}
);
}
);
}
}
module.exports = ChunksRenamePlugin;