-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
115 lines (101 loc) · 2.61 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
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
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var isDev = (process.argv[1] || '').indexOf('webpack-dev-server') !== -1;
var entry = path.resolve('./client');
var hostname = process.env.HOSTNAME || 'localhost';
var port = Number(process.env.DEVPORT || 8080);
var urlLoaderLimit = Number(process.env.URLLOADERLIMIT || 10000);
var output = {
path: path.join(__dirname, '/dist/'),
filename: 'app.js',
publicPath: '/dist/'
};
var defaultLoaders = [
{
test: /\.json$/,
exclude: /node_modules/,
loader: 'json'
},
{
test: /\.(otf|eot|svg|ttf|woff)/,
loader: 'url-loader?limit=' + urlLoaderLimit
}, {
test: /\.(jpe?g|png|gif)/,
loader: 'url-loader?limit=' + urlLoaderLimit
}
];
var devConfig = {
devtool: 'eval',
entry: [
entry,
'webpack-dev-server/client?http://' + hostname + ':' + port,
'webpack/hot/only-dev-server'
],
output: output,
devServer: {
proxy: {
'*': 'http://localhost:' + (process.env.PORT || 3000)
}
},
module: {
preLoaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: "eslint-loader"
}],
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'react-hot!babel-loader',
}, {
test: /\.css$/,
exclude: /node_modules/,
loader: ExtractTextPlugin.extract('style', 'css?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!cssnext-loader')
}].concat(defaultLoaders)
},
plugins: [
new ExtractTextPlugin('app.css', {
allChunks: true
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.DefinePlugin({
'process.env': {NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development')}
})
]
}
var prodConfig = {
entry: [ entry ],
output: output,
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
}, {
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!postcss-loader')
}].concat(defaultLoaders)
},
plugins: [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(true),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
output: {
comments: false
},
sourceMap: false
}),
new ExtractTextPlugin('[name].css', {
allChunks: true
}),
new webpack.DefinePlugin({
'process.env': {NODE_ENV: JSON.stringify('production')}
})
]
}
module.exports = isDev ? devConfig : prodConfig;