-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
89 lines (87 loc) · 2.25 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
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
const DefinePlugin = require('webpack/lib/DefinePlugin');
const CompressionPlugin = require("compression-webpack-plugin");
const webpack = require('webpack');
module.exports = {
entry: {
app: ['./src/entry.jsx'],
common: [
'react', 'react-dom', 'react-router',
'redux', 'react-redux','object-assign', 'redux-saga',
'react-router-redux', 'whatwg-fetch', 'babel-polyfill',
],
},
output: {
path: `${__dirname}/dist`,
filename: '[name].bundle.js',
publicPath: './dist/',
},
resolve: {
extensions: ['', '.js', '.jsx', '.json'],
},
module: {
loaders: [
{
test: /\.js(x$|$)/,
loaders: ['babel'],
exclude: /node_modules/,
},
{
test: /\.css$/,
loaders: ['style', 'css?modules&localIdentName=[name]__[local]-[hash:base64:5]'],
},
{
test: /\.json/,
loaders: ['json'],
},
{
test: /\.(png|jpg|jpeg|gif)$/,
loaders: ['file?name=[hash:base64:7].[ext]'],
},
],
},
plugins: [
new DefinePlugin({
process: {
env: {
CURRENT_VERSION: JSON.stringify(process.env.CURRENT_VERSION || '内部测试'),
NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
// BASE_URI: JSON.stringify(process.env.BASE_URI || '/index.php/Home'),
},
},
}),
new webpack.optimize.CommonsChunkPlugin({
name: ['common', 'manifest'],
filename: '[name].chunk.js',
minChunks: Infinity,
}),
].concat((() => {
if (process.env.NODE_ENV === 'production') {
return [
new webpack.optimize.UglifyJsPlugin({
minimize: true,
mangle: true,
compress: {
warnings: false, // Suppress uglification warnings
pure_getters: true,
unsafe: true,
unsafe_comps: true,
screw_ie8: true
},
output: {
comments: false,
},
exclude: [/\.min\.js$/gi],
}),
new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0
}),
];
}
return [];
})()),
externals: { },
};