yo.prod.conf.js
2.82 KB
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
65
66
67
68
69
const _ = require('lodash');
const ManifestPlugin = require('webpack-manifest-plugin');
const yoBase = require('./yo.base.conf.js');
const yo = require('yo-cli');
const pkg = require('../package.json');
module.exports = yo(yoBase)
.style({
extract: true
})
.sourceMap()
.merge({
plugins: [
new ManifestPlugin({
fileName: `${pkg.version}/manifest.json`,
generate(seed, files) {
const result = {
common: {},
pages: {},
};
_.each(files, (file => {
const {name, path: filePath} = file;
const match = /page\.([^\.]+)\.([^\.]+)\.js$/.exec(name);
if (match) {
const [, moduleName, pageName] = match;
if (!result.pages[moduleName]) {
result.pages[moduleName] = {};
}
if (result.pages[moduleName][pageName]) {
throw Error(`页面文件名称冲突:${moduleName}.${pageName}`);
}
result.pages[moduleName][pageName] = {
js: filePath
};
const cssFile = _.find(files,
({name: fname}) => fname === `page.${moduleName}.${pageName}.css`);
if (cssFile) {
result.pages[moduleName][pageName].css = cssFile.path;
}
} else if (name === 'main.js') {
result.common.main = {
js: filePath,
css: _.get(_.find(files, ({name: fname}) => fname === 'main.css'), 'path')
};
} else if (name === 'runtime-main.js') {
result.common.runtime = {
js: filePath
};
} else if (name === 'vendors.js') {
result.common.vendors = {
js: filePath,
css: _.get(_.find(files, ({name: fname}) => fname === 'vendors.css'), 'path')
};
} else if (name === 'index.css') {
result.common.index = {
css: _.get(_.find(files, ({name: fname}) => fname === 'index.css'), 'path')
};
}
}));
return result;
}
}),
]
})
.run();