-
Notifications
You must be signed in to change notification settings - Fork 536
/
Copy pathwebpack.prod.conf.js
63 lines (58 loc) · 1.74 KB
/
webpack.prod.conf.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
var webpack = require('webpack'),
config = require('./webpack.base.conf'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
CopyWebpackPlugin = require('copy-webpack-plugin'),
CleanWebpackPlugin = require('clean-webpack-plugin'),
ExtractTextPlugin = require('extract-text-webpack-plugin'),
SOURCE_MAP = false;
config.output.filename = '[name].[chunkhash:6].js';
config.output.chunkFilename = '[id].[chunkhash:6].js';
config.devtool = SOURCE_MAP ? 'source-map' : false;
// 生产环境下分离出 CSS 文件
config.module.loaders.push({
test: /\.css$/,
loader: ExtractTextPlugin.extract('style', 'css')
}, {
test: /\.less$/,
loader: ExtractTextPlugin.extract('style', 'css!less')
}, {
test: /\.scss$/,
loader: ExtractTextPlugin.extract('style', 'css!sass')
});
config.plugins.push(
new CleanWebpackPlugin('dist', {
root: config.commonPath.rootPath,
verbose: false
}),
new CopyWebpackPlugin([ // 复制高度静态资源
{
context: config.commonPath.staticDir,
from: '**/*',
ignore: ['*.md']
}
]),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.CommonsChunkPlugin({
// 公共代码分离打包
names: ['vendor', 'mainifest']
}),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.optimize.MinChunkSizePlugin({
minChunkSize: 30000
}),
new ExtractTextPlugin('[name].[contenthash:6].css', {
allChunks : true // 若要按需加载 CSS 则请注释掉该行
}),
new HtmlWebpackPlugin({
filename: '../index.html',
template: config.commonPath.indexHTML,
chunksSortMode: 'none'
})
);
module.exports = config;