|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 | 3 |
|
| 4 | +var path = require('path'); |
4 | 5 | var webpack = require('webpack');
|
5 | 6 |
|
6 | 7 |
|
7 |
| -module.exports = { |
| 8 | +// Detect if we're running webpack dev server or building a distribution. |
| 9 | +var devServer = path.basename(require.main.filename) === 'webpack-dev-server.js'; |
| 10 | + |
| 11 | + |
| 12 | +var config = { |
8 | 13 | plugins: [
|
9 |
| - new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), |
10 |
| - new webpack.optimize.DedupePlugin(), |
11 |
| - new webpack.optimize.UglifyJsPlugin({compress: {drop_console: true}}), |
12 |
| - new webpack.optimize.OccurenceOrderPlugin(), |
13 |
| - new webpack.optimize.AggressiveMergingPlugin() |
| 14 | + new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/) |
14 | 15 | ],
|
15 | 16 |
|
16 | 17 | entry: './scripts/init.jsx',
|
@@ -69,3 +70,35 @@ module.exports = {
|
69 | 70 | debug: false,
|
70 | 71 | devtool: false
|
71 | 72 | };
|
| 73 | + |
| 74 | + |
| 75 | +if (devServer) { |
| 76 | + config.plugins.push( |
| 77 | + new webpack.HotModuleReplacementPlugin(), |
| 78 | + new webpack.NoErrorsPlugin(), |
| 79 | + new webpack.DefinePlugin({'process.env.NODE_ENV': '"development"'}) |
| 80 | + ); |
| 81 | + config.entry = [ |
| 82 | + 'webpack/hot/only-dev-server', |
| 83 | + './scripts/init.jsx' |
| 84 | + ]; |
| 85 | + config.devServer = { |
| 86 | + hot: true |
| 87 | + }; |
| 88 | + config.output.publicPath = '/dist/'; |
| 89 | + config.module.loaders[0].loader = 'react-hot!babel-loader?stage=1&optional=runtime'; |
| 90 | + config.cache = true; |
| 91 | + config.debug = true; |
| 92 | + config.devtool = 'eval'; |
| 93 | +} else { |
| 94 | + config.plugins.push( |
| 95 | + new webpack.optimize.DedupePlugin(), |
| 96 | + new webpack.optimize.UglifyJsPlugin({compress: {drop_console: false}}), |
| 97 | + new webpack.optimize.OccurenceOrderPlugin(), |
| 98 | + new webpack.optimize.AggressiveMergingPlugin(), |
| 99 | + new webpack.DefinePlugin({'process.env.NODE_ENV': '"production"'}) |
| 100 | + ); |
| 101 | +} |
| 102 | + |
| 103 | + |
| 104 | +module.exports = config; |
0 commit comments