-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.dev.js
66 lines (58 loc) · 2.18 KB
/
webpack.dev.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
import assign from 'object-assign';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import path from 'path';
import productionConfiguration from './webpack.config.js';
import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
/**
* Webpack configuration for development.
* Using `assign`, it is derived from the production configuration.
*/
export default function(app) {
const config = productionConfiguration;
//add SourceMap as DataUrl to the JavaScript file
config.devtool = 'inline-source-map';
//allow hot swapping
config.entry.unshift('webpack-hot-middleware/client');
//configure the `react transform` plugin
config.module.loaders[0].query.plugins.push(
['transform-object-rest-spread'],
['transform-class-properties'],
['transform-decorators-legacy'],
['react-transform', {
transforms: [{
transform: 'react-transform-hmr',
imports: ['react'],
locals: ['module']
}]
}
]
);
//augment the plugin array
config.plugins.unshift(
//all the following three plugins are required by the webpackHotMiddleware middleware
//assign the module and chunk ids by occurrence count -> ids that are used often get lower (shorter) ids
new webpack.optimize.OccurrenceOrderPlugin(),
//hot reload plugin
new webpack.HotModuleReplacementPlugin(),
//do not exit with a fail code on encountering an error during compilation; skip emitting phase instead
new webpack.NoErrorsPlugin(),
//set the BROWSER variable to true (useful for determining context in the shared code base)
new webpack.DefinePlugin({
"process.env": {
BROWSER: JSON.stringify(true)
}
})
);
console.log(config.module.loaders[0].query.plugins);
//"load" the configuration
const compiler = webpack(config);
//serve the files emitted from webpack over a connect server (nothing is written to the disk)
app.use(webpackDevMiddleware(compiler, {
// display all info to console (not only warnings and errors)
noInfo: false
}));
//allow webpack hot reloading
app.use(webpackHotMiddleware(compiler));
}