-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
56 lines (51 loc) · 1.69 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
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const appPath = path.resolve(__dirname, 'client');
const buildPath = path.resolve(__dirname, 'public', 'assets');
const isDev = process.env.NODE_ENV !== 'production';
const defaultStyleLoaders = ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader'],
});
const common = {
context: __dirname,
output: {
path: buildPath,
filename: 'bundle.js',
publicPath: '/assets/',
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(isDev ? 'development' : 'production')
}),
new ExtractTextPlugin('index.css'),
],
};
if (isDev) {
module.exports = merge(common, {
entry: ['webpack-hot-middleware/client', path.resolve(appPath, '_dev.js'), path.resolve(appPath, 'index.js')],
devtool: 'eval-source-map',
module: {
loaders: [
{ test: /\.js$/, loaders: ['react-hot-loader', 'babel-loader'], exclude: [/node_modules/] },
{ test: /\.scss$/, loaders: ['css-hot-loader', ...defaultStyleLoaders] },
{ test: require.resolve('react-addons-perf'), loader: 'expose-loader?Perf' },
],
},
plugins: [new webpack.HotModuleReplacementPlugin()],
});
} else {
module.exports = merge(common, {
entry: path.resolve(appPath, 'index.js'),
devtool: 'cheap-module-source-map',
module: {
loaders: [
{ test: /\.js$/, loader: 'babel-loader', exclude: [/node_modules/] },
{ test: /\.scss$/, use: defaultStyleLoaders },
],
},
plugins: [new webpack.optimize.UglifyJsPlugin()],
});
}