-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
45 lines (42 loc) · 1.14 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
45
const name = 'WebpackEntrypointsPlugin'
const fs = require('fs');
class WebpackEntrypointsPlugin {
constructor(options) {
this.path = options.path;
this.change = options.change;
}
apply(compiler) {
compiler.hooks.done.tap(name, (stats) => {
const chunkOnlyConfig = {
assets: false,
cached: false,
children: true,
chunks: true,
chunkModules: false,
chunkOrigins: false,
errorDetails: false,
hash: false,
modules: false,
reasons: false,
source: false,
timings: false,
version: false
};
const entrypoints = stats.toJson(chunkOnlyConfig).entrypoints;
const path = this.path;
let data = {};
if (fs.existsSync(path)) {
data = JSON.parse(fs.readFileSync(path).toString());
}
for (let en in entrypoints) {
data[en] = {
chunks: entrypoints[en].chunks,
assets: entrypoints[en].assets,
}
}
path && fs.writeFileSync(path, JSON.stringify(data, null, '\t'));
this.change && this.change(data);
})
}
}
module.exports = WebpackEntrypointsPlugin;