-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
53 lines (51 loc) · 1.43 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
51
52
53
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
var webpackConfig = {
entry: {
aa: ['./src/js/pages/aa.js'],
bb: ['./src/js/pages/bb.js']
},
output: {
path: path.resolve(__dirname, 'dest'),
filename: 'js/[hash:8].[name].js',
},
module: {
loaders: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
},
{
test: /\.json$/,
loader: 'json'
}
]
},
plugins: [
new ExtractTextPlugin('css/[contenthash:8].[name].css', {
//allChunks: true
}),
new CommonsChunkPlugin({
name: 'vendors',
chunks: ['aa', 'bb'],
// minChunks是指一个文件至少被require几次才会被放到CommonChunk里,如果minChunks等于2,说明一个文件至少被require两次才能放在CommonChunk里
minChunks: 2 // 提取所有chunks共同依赖的模块
}),
new HtmlWebpackPlugin({
inject: 'body',
chunks: ['vendors', 'aa'],
filename: 'html/a.html',
template: 'src/html/a.html',
}),
new HtmlWebpackPlugin({
inject: 'body',
chunks: ['vendors', 'bb'],
filename: 'html/b.html',
template: 'src/html/b.html',
})
]
}
module.exports = webpackConfig;