-
Notifications
You must be signed in to change notification settings - Fork 9
/
webpack.config.js
87 lines (80 loc) · 2.44 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
var webpack = require('webpack');
var path = require('path');
var CDN_URL = '';
var EXTERNALS = { // dev 这里应该不加 react 和 react-dom 的 external, build 要加
'react': 'window.React',
'react-dom': 'window.ReactDOM'
};
console.log('process.env.NODE_ENV in webpack config::::', process.env.NODE_ENV);
if (!process.env.NODE_ENV) process.env.NODE_ENV = 'dev-HMR';
if (process.env.NODE_ENV === 'dev-HMR') {
CDN_URL = 'http://localhost:8088/';
}
if (process.env.NODE_ENV === 'pre') CDN_URL = '//localhost:5000/';
if (process.env.NODE_ENV === 'production') CDN_URL = 'https://we-voting-ele.herokuapp.com/';
var config = {
entry: {
vote: [
'./client/index.jsx'
],
router: ['react-router'] // CommonsChunkPlugin
},
output: {
path: path.resolve(__dirname, './dist'),
publicPath: CDN_URL + 'dist/', // 静态资源文件内的请求路径指向静态资源服务器
filename: '[name].bundle.js',
chunkFilename: '[name].chunk.js'
},
externals: EXTERNALS,
devtool: process.env.NODE_ENV === 'dev-HMR' ? 'eval-source-map' : '',
module: {
loaders: [
{
test: /\.js$|\.jsx$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015']
}
},
{
test: /\.js$|\.jsx$/,
exclude: /node_modules/,
loader: 'eslint-loader'
}
]
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(), // 比对id的使用频率和分布来得出最短的id分配给使用频率高的模块
new webpack.HotModuleReplacementPlugin(), // 同命令行中的 --hot
new webpack.optimize.CommonsChunkPlugin('router', '[name].bundle.js'), // CommonsChunk
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
output: {
comments: false // remove all comments
}
}),
new webpack.DefinePlugin({
// The DefinePlugin allows you to create global constants which can be configured at compile time.
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
}
})
],
resolve: {
root: path.resolve(__dirname, './client'),
fallback: [path.resolve(__dirname, './node_modules')],
extensions: ['', '.js', '.jsx']
},
devServer: {
hot: process.env.NODE_ENV === 'dev-HMR',
inline: true,
headers: { 'Access-Control-Allow-Origin': '*' }
},
eslint: {
configFile: './.eslintrc'
}
};
module.exports = config;