-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (56 loc) 路 1.91 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const ManifestPlugin = require('webpack-manifest-plugin');
const defaultOptions = {
filePath: './../manifest',
};
function modify(baseConfig, { target, dev }, webpack, userOptions = {}) {
const config = Object.assign({}, baseConfig);
const options = Object.assign({}, defaultOptions, userOptions);
if (target === 'web') {
config.plugins.push(
// based on https://github.com/danethurber/webpack-manifest-plugin/issues/181#issuecomment-467907737
new ManifestPlugin({
fileName: options.filePath.concat('.json'),
writeToFileEmit: true,
filter: item => item.isChunk,
generate: (seed, files) => {
const entrypoints = new Set();
files.forEach(file =>
((file.chunk || {})._groups || []).forEach(group =>
entrypoints.add(group)
)
);
const entries = [...entrypoints];
const entryArrayManifest = entries.reduce((acc, entry) => {
const name =
(entry.options || {}).name || (entry.runtimeChunk || {}).name;
const files = []
.concat(
...(entry.chunks || []).map(chunk =>
chunk.files.map(path => baseConfig.output.publicPath + path)
)
)
.filter(Boolean);
const cssFiles = files
.map(item => (item.indexOf('.css') !== -1 ? item : null))
.filter(Boolean);
const jsFiles = files
.map(item => (item.indexOf('.js') !== -1 ? item : null))
.filter(Boolean);
return name
? {
...acc,
[name]: {
css: cssFiles,
js: jsFiles,
},
}
: acc;
}, seed);
return entryArrayManifest;
},
})
);
}
return config;
}
module.exports = modify;