forked from Andy-K-Sparklight/Alicorn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildInfoPlugin.js
39 lines (37 loc) · 1.13 KB
/
BuildInfoPlugin.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
// MAINTAINERS ONLY
class BuildInfoPlugin {
constructor(output, version) {
this.output = output;
this.version = version;
}
apply(compiler) {
const pluginName = BuildInfoPlugin.name;
const { webpack } = compiler;
const { Compilation } = webpack;
const { RawSource } = webpack.sources;
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
compilation.hooks.processAssets.tap(
{
name: pluginName,
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE,
},
(assets) => {
const bInfo = {};
bInfo.date = new Date().toUTCString();
bInfo.files = Array.from(Object.keys(assets)).filter(
(v) =>
!v.toUpperCase().includes("LICENSE") &&
!v.toLowerCase().endsWith(".d.ts") &&
!v.toLowerCase().endsWith(".map")
); // Do not send unnecessary files to client
bInfo.version = this.version;
compilation.emitAsset(
this.output,
new RawSource(JSON.stringify(bInfo))
);
}
);
});
}
}
module.exports = BuildInfoPlugin;