forked from alfa-laboratory/arui-feather
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.js
65 lines (57 loc) · 1.85 KB
/
demo.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
/* eslint import/no-extraneous-dependencies: [2, {"devDependencies": true}] */
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const webpackConfig = require('./webpack.config.js');
const HOT_LOADER = !!process.env.HOT_LOADER;
const PORT = process.env.PORT ? process.env.PORT : 8080;
const HOST = process.env.HOST || 'localhost';
webpackConfig.entry = Object.keys(webpackConfig.entry).reduce((result, item) => {
result[item] = [
'webpack/hot/only-dev-server',
`webpack-dev-server/client?http://${HOST}:${PORT}`
];
if (HOT_LOADER) {
result[item] = result[item].concat('react-hot-loader/patch');
}
result[item] = result[item].concat(webpackConfig.entry[item]);
return result;
}, {});
if (HOT_LOADER) {
webpackConfig.module.loaders
.filter(loader => loader.loader === 'babel')
.forEach((loader) => {
if (loader.query && loader.query.plugins) {
loader.query.plugins = ['react-hot-loader/babel'].concat(loader.query.plugins);
}
});
}
webpackConfig.plugins.push(new webpack.HotModuleReplacementPlugin());
const compiler = webpack(webpackConfig);
const server = new WebpackDevServer(compiler, {
contentBase: webpackConfig.output.path,
hot: true,
quiet: false,
noInfo: false,
inline: true,
lazy: false,
filename: webpackConfig.output.filename,
watchOptions: {
aggregateTimeout: 300,
poll: 1000
},
publicPath: '/',
disableHostCheck: true,
stats: {
colors: true,
assets: false,
version: false,
hash: false,
timings: true,
chunks: false,
chunkModules: false
}
});
server.listen(PORT, HOST, function () {
// eslint-disable-next-line no-console
console.log(`Server running at http://${HOST}:${PORT}/`);
});