-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
66 lines (57 loc) · 1.54 KB
/
server.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
const { resolve } = require('path');
const webpack = require('webpack');
const express = require('express');
const DashboardPlugin = require('webpack-dashboard/plugin');
const config = require('./webpack/webpack.config.development.js');
const HOST = process.env.HOST || '0.0.0.0';
const PORT = process.env.PORT || 8600;
const app = express();
const compiler = webpack(config);
/*
compiler.apply(
new DashboardPlugin()
);
*/
const hot = require('webpack-hot-middleware')(compiler);
const dev = require('webpack-dev-middleware')(compiler, {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
// It suppress error shown in console, so it has to be set to false.
quiet: false,
// It suppress everything except error, so it has to be set to false as well
// to see success build.
noInfo: false,
stats: {
// Config for minimal console.log mess.
assets: false,
colors: true,
version: false,
hash: false,
timings: false,
chunks: false,
chunkModules: false
},
headers: {
'Access-Control-Allow-Origin': '*'
}
});
app.use(dev);
app.use(hot);
app.get('*', function (req, res, next) {
const filename = resolve(compiler.outputPath, 'index.html');
compiler.outputFileSystem.readFile(filename, function(err, result) {
if (err) {
return next(err);
}
res.set('content-type','text/html');
res.send(result);
res.end();
});
});
app.listen(PORT, HOST, err => {
if (err) {
return console.error(err);
}
console.log(`Listening at http://${HOST}:${PORT}/`);
});