-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (34 loc) · 1.07 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
"use strict";
module.exports = class RenameModule {
constructor(options) {
this.options = [];
if (options) {
if (Array.isArray(options)) {
this.options.push(...options);
}
else {
this.options.push(options);
}
}
}
apply(compiler) {
if (!this.options.length)
return;
const chunksForEach = (chunk) => {
if (chunk.entryModule && chunk.entryModule.resource) {
const find = (item) => {
return item.origin.test(chunk.entryModule.resource);
};
const matched = this.options.find(find);
if (matched) {
chunk.filenameTemplate = matched.outputName;
}
}
};
compiler.hooks.thisCompilation.tap("rename-webpack-plugin", (compilation) => {
compilation.hooks.optimizeChunks.tap("rename-webpack-plugin", (chunks) => {
chunks.forEach(chunksForEach);
});
});
}
};