-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.config.js
executable file
·81 lines (78 loc) · 2.18 KB
/
webpack.prod.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict';
var path = require('path');
var webpack = require('webpack');
var uglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
// 产出html模板
var HtmlWebpackPlugin = require("html-webpack-plugin");
// 单独样式文件
var ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
entry: [
path.resolve(__dirname, 'app/main.jsx')
],
output: {
path: path.resolve(__dirname, 'build'),
filename: "[name].[hash:8].js",
publicPath: '/'
},
resolve: {
extension: ['', '.jsx', '.js', '.json'],
alias: {}
},
'display-error-details': true,
module: {
loaders: [
{
test: /\.js[x]?$/,
loaders: ['babel-loader'],
exclude: path.resolve(__dirname, 'node_modules')
},
{
test: /\.scss$/,
include: path.resolve(__dirname, 'app'),
loader: 'style!css!sass?sourceMap'
},
{
test: /\.css/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader")
},
{
test: /\.(png|jpg|gif)$/,
loader: 'url?limit=8192'
},
{
test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
loader : 'file-loader'
}
]
},
plugins: [
new ExtractTextPlugin("main.[hash:8].css", {
allChunks: true,
disable: false
}),
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.[hash:8].js'),
new uglifyJsPlugin({
compress: {
warnings: false
}
}),
new HtmlWebpackPlugin({
title: 'your app title',
template: './app/index.html',
}),
new webpack.optimize.MinChunkSizePlugin({
compress: {
warnings: false
}
}),
// 查找相等或近似的模块,避免在最终生成的文件中出现重复的模块
new webpack.optimize.DedupePlugin(),
// 按引用频度来排序 ID,以便达到减少文件大小的效果
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.AggressiveMergingPlugin({
minSizeReduce: 1.5,
moveToParents: true
}),
]
};