-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
jsonmanifest-plugin.js
42 lines (37 loc) · 1.49 KB
/
jsonmanifest-plugin.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
const webpack = require("webpack");
module.exports = class JSONManifestPlugin {
constructor(options) {
this.version = options.version;
}
apply(compiler) {
compiler.hooks.compilation.tap("JSONManifestPlugin", compilation => {
compilation.hooks.processAssets.tapPromise(
{
name: "JSONManifestPlugin",
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT
},
async () => {
const result = { manifestVersion: 1, version: this.version, entries: [] };
for (const entrypoint of compilation.entrypoints.values()) {
for (const chunk of entrypoint.chunks) {
result.entries = result.entries.concat(
[...chunk.files.values()].filter(
val => val.endsWith(".js") && !val.endsWith(".hot-update.js")
)
);
}
}
const processed = JSON.stringify(result);
compilation.assets["webpanelmanifest.json"] = {
source: () => {
return processed;
},
size: () => {
return processed.length;
}
};
}
);
});
}
};