-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.prod.js
More file actions
174 lines (171 loc) · 5.91 KB
/
webpack.prod.js
File metadata and controls
174 lines (171 loc) · 5.91 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const pathLib = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const CleanPlugin = require('clean-webpack-plugin');
const ROOT_PATH = pathLib.resolve(__dirname);
const ENTRY_PATH = pathLib.resolve(ROOT_PATH, 'src');
const ENTRY_PATH_PAGES = pathLib.resolve(ROOT_PATH, 'src/pages');
const OUTPUT_PATH = pathLib.resolve(ROOT_PATH, 'build');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = {
entry: {
index: ['babel-polyfill',pathLib.resolve(ENTRY_PATH_PAGES, './index/index.js')],
admin: ['babel-polyfill',pathLib.resolve(ENTRY_PATH_PAGES, './admin/index.js')],
vendor: ['react', 'react-dom', 'react-router-dom', 'redux', 'react-redux', 'redux-saga', 'react-hot-loader/patch', ]
},
output: {
path: OUTPUT_PATH,
publicPath: '/',
filename: '[name]-[chunkhash].js'
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test:/\.css$/,
exclude:/node_modules/,
use:ExtractTextPlugin.extract({
fallback:'style-loader',
use:[
{
loader:'css-loader',
options:{
modules:true,
localIdentName:'[name]-[local]-[hash:base64:5]',
importLoaders:1
}
},
'postcss-loader'
]
})
},
{
test: /\.css$/,
include: /node_modules/,
use: ['style-loader',
{
loader: 'css-loader'
},
'postcss-loader'
]
},
{
test: /\.less$/,
use: ["style-loader", 'css-loader', "postcss-loader", "less-loader"]
},
{
test: /\.(png|jpg|gif|JPG|GIF|PNG|BMP|bmp|JPEG|jpeg)$/,
exclude: /node_modules/,
use: [
{
loader: 'url-loader',
options: {
limit: 8192
}
}
]
},
{
test: /\.(eot|woff|ttf|woff2|svg)$/,
use: 'url-loader'
}
]
},
plugins: [
//打包分析工具
//new BundleAnalyzerPlugin(),
new CleanPlugin(['build']),
new ProgressBarPlugin(),
new webpack.optimize.AggressiveMergingPlugin(),//改善chunk传输
//new webpack.DefinePlugin({
// "progress.env.NODE_ENV": JSON.stringify('production')
//}),
new webpack.DefinePlugin({
"progress.env.NODE_ENV": JSON.stringify('production')
}),
// new webpack.DefinePlugin({
// "process.env": {
// "NODE_ENV": JSON.stringify("production")
// }
// }),
//new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.UglifyJsPlugin({
sourceMap: false,
show_copyright: false,
comments: false,
compress: {
warnings: false,
drop_debugger: true,
drop_console: true
}
}),
/*new HtmlWebpackPlugin({
title: "Nitrohe's Blog",
showErrors: true,
}),*/
new HtmlWebpackPlugin({
title: "Nitrohe's Blog",
meta:{
keywords: "",
description: "Nitrohe's Blog"
},
//chunks:[`${item}/${item}`], //引入的js
//template: "./src/template.html",
filename : "index.html" , //html位置
minify:{//压缩html
collapseWhitespace: true,
preserveLineBreaks: true
},
chunks: ['manifest', 'vendor', 'index'],
chunksSortMode:'dependency'
}),
new HtmlWebpackPlugin({
title: "Nitrohe's Admin",
meta:{
keywords: "",
description: "Nitrohe's Admin"
},
//chunks:[`${item}/${item}`], //引入的js
//template: "./src/template.html",
filename : "admin.html" , //html位置
minify:{//压缩html
collapseWhitespace: true,
preserveLineBreaks: true
},
chunks: ['manifest', 'vendor', 'admin'],
chunksSortMode:'dependency'
}),
new webpack.NoEmitOnErrorsPlugin(),//保证出错时页面不阻塞,且会在编译结束后报错
new ExtractTextPlugin({
filename:'bundle.[contenthash].css',
disable:false,
allChunks:true
}),
new webpack.HashedModuleIdsPlugin(),//用 HashedModuleIdsPlugin 可以轻松地实现 chunkhash 的稳定化
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: function (module) {
return module.context && module.context.indexOf('node_modules') == -1;
}
}),
new webpack.optimize.CommonsChunkPlugin({
name: "manifest"
})
],
resolve: {
alias:{
'@components':pathLib.resolve(__dirname,'./src/components'),
'@reducers':pathLib.resolve(ROOT_PATH, './src/reducers'),
//'@reducers':'./src/reducers',
'@mlib':pathLib.resolve(__dirname,'./mlib')
},
extensions: ['.js', '.json', '.sass', '.scss', '.less', 'jsx']
}
};