-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.js
67 lines (63 loc) · 1.71 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
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var AssetsPlugin = require('assets-webpack-plugin');
var assetsPluginInstance = new AssetsPlugin();
const DEBUG = !process.argv.includes('--release');
const DEVELOP = process.argv.includes('--develop');
const devtool = DEBUG ? 'eval' : 'cheap-module-source-map';
let entry = ['./src/index.js'];
const output = {
path: __dirname,
filename: DEBUG ? 'static/js/bundle.js' : 'static/js/bundle.[chunkhash].js',
publicPath: '/'
};
const innerModule = {
loaders: [
{
test: /.jsx?$/,
exclude: /node_modules/,
loaders: ['babel-loader?presets[]=es2015,presets[]=react']
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract(
'style', // backup loader when not building .css file
'css!sass' // loaders to preprocess CSS
)
}
]
};
const plugins = [
new ExtractTextPlugin( DEBUG ? 'static/css/bundle.css' : 'static/css/bundle.[contenthash].css', {
allChunks: true
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': DEBUG ? '"development"' : '"production"',
}),
assetsPluginInstance,
];
if (DEVELOP) {
entry = entry.concat([
'webpack-dev-server/client?http://0.0.0.0:8080', // WebpackDevServer host and port
'webpack/hot/only-dev-server' // "only" prevents reload on syntax errors
]);
output.publicPath = 'http://localhost:8080/';
innerModule.loaders[0].loaders.splice(0, 0, 'react-hot')
}
if (!DEBUG) {
plugins.push(
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false
}
})
)
}
module.exports = {
devtool,
entry,
output,
module: innerModule,
plugins,
};