-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdevmode.js
58 lines (46 loc) · 1.27 KB
/
devmode.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
var path = require('path');
var webpack = require('webpack');
var webpackConfig = require('./webpack.config');
module.exports = function(app, callback) {
// Enabled hotload mechanism
webpackConfig.forEach(function(config) {
if (config.name != 'Browser')
return;
if (!(config.entry.app instanceof Array)) {
config.entry.app = [
config.entry.app
];
}
config.entry.app.splice(0, 0, 'webpack-hot-middleware/client');
config.plugins.push(new webpack.HotModuleReplacementPlugin());
for (var index in config.module.loaders) {
var loader = config.module.loaders[index];
if (loader.loader != 'babel')
continue;
if (!loader.query)
continue;
loader.query.plugins.push([
'react-transform', {
'transforms': [{
'transform': 'react-transform-hmr',
'imports': ['react'],
'locals': ['module']
}, {
'transform': 'react-transform-catch-errors',
'imports': ['react', 'redbox-react']
}]
}
]);
}
// Compiling now
var compiler = webpack(config);
compiler.run(function(err, stats) {
app.use(require('koa-webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
app.use(require('koa-webpack-hot-middleware')(compiler));
callback();
});
});
};