-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
50 lines (49 loc) · 1.67 KB
/
webpack.config.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
const argv = require('yargs-parser')(process.argv.slice(2));
const _mergeMode = argv['mode'];
const {resolve} = require('path');
const _mergeConfig = require(resolve(__dirname, './', `config/webpack.${_mergeMode}.js`));
const merge = require('webpack-merge');
const glob = require('glob');
const htmlWebpackPlugin = require('html-webpack-plugin');
const htmlAfterWebpackPlugin = require('./config/htmlAfterWebpackPlugin');
const entries = {}
const _plugins = [];
// 获取入口文件
const files = glob.sync('./src/client/views/**/*.entry.js');
for (let item of files) {
if (/.+\/([a-zA-Z0-9]+-[a-zA-Z0-9]+)(\.entry\.js$)/g.test(item)) {
const entryKeys = RegExp.$1;
const [dir, name] = entryKeys.split('-');
// console.log(dir, name);
_plugins.push(new htmlWebpackPlugin({
filename: `../views/${dir}/pages/${name}.html`, // 发布到远程
chunks: ['runtime', entryKeys], // 配置加载需要的模块
template: resolve(__dirname, './', `src/client/views/${dir}/pages/${name}.html`),
inject: false // 不注入js或css
}));
entries[entryKeys] = item;
}
}
const config = {
entry: entries,
output: {
// publicPath: '/',
path: resolve(__dirname, './dist/assets/'),
filename: 'scripts/[name].[hash:8].bundle.js'
},
plugins: [
..._plugins,
new htmlAfterWebpackPlugin(),
],
resolve: {
alias: { // 别名
'@': resolve('./src/client/components')
}
},
optimization: {
runtimeChunk: { // 抽取运行时公共代码
name: 'runtime'
}
}
};
module.exports = merge(config, _mergeConfig);