-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwebpack.config.js
45 lines (44 loc) · 1.38 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
const Webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackMd5Hash = require('webpack-md5-hash');
module.exports = function(config, env) {
config.module.loaders[0].exclude.push(/\.ejs$/); // 注 1
if (env === 'production') {
config.output.filename = '[name].[chunkhash].js';
config.output.chunkFilename = '[chunkhash].async.js';
config.plugins[3] = new ExtractTextPlugin('[contenthash:20].css'); // 注 2
for (let plugin, i = 0, l = config.plugins.length; i < l; i++) {
plugin = config.plugins[i];
if (plugin instanceof Webpack.optimize.CommonsChunkPlugin) {
config.plugins[i] = new Webpack.optimize.CommonsChunkPlugin({
name: 'common',
filename: 'common.[chunkhash].js',
minChunks: 2
});
break;
}
}
config.plugins.push(
new HtmlWebpackPlugin({
template: 'ejs!src/index.ejs', // 注 3
inject: false,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: false
},
production: true
}),
new WebpackMd5Hash()
);
} else {
config.plugins.push(
new HtmlWebpackPlugin({
template: 'ejs!src/index.ejs',
inject: true
}),
);
}
return config;
};