-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
36 lines (32 loc) · 986 Bytes
/
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
const { join } = require('path');
const webpack = require('webpack');
const express = require('express');
const devMiddleware = require('webpack-dev-middleware');
const hotMiddleware = require('webpack-hot-middleware');
const getConfig = require('./webpack.config');
const app = express();
const config = getConfig({ development: true });
const compiler = webpack(config);
app.use(devMiddleware(compiler, {
publicPath: config.output.publicPath,
historyApiFallback: true,
noInfo: true,
stats: 'errors-only',
}));
app.use(hotMiddleware(compiler));
app.use('*', (req, res, next) => {
const filename = join(compiler.outputPath, 'index.html');
compiler.outputFileSystem.readFile(filename, (err, result) => {
if (err) {
return next(err);
}
res.set('content-type', 'text/html');
res.send(result);
return res.end();
});
});
/* eslint-disable no-console */
app.listen(3000, (err) => {
if (err) console.error(err);
});
/* eslint-enable no-console */