-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevServer.ts
More file actions
28 lines (23 loc) · 855 Bytes
/
devServer.ts
File metadata and controls
28 lines (23 loc) · 855 Bytes
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
/* tslint:disable no-console */
const express = require('express');
const webpack = require('webpack');
const webpackMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const { port } = require('./config');
const config = require('./config/webpack/dev.ts');
const app = express();
const compiler = webpack(config);
const middleware = webpackMiddleware(compiler, {
logLevel: 'error',
headers: { 'Access-Control-Allow-Origin': '*' },
stats: { colors: true },
});
app.use(middleware);
app.use(webpackHotMiddleware(compiler));
app.get('*', (req, res) => {
const htmlBuffer = middleware.fileSystem.readFileSync(`${config.output.path}/index.html`);
res.send(htmlBuffer.toString());
});
app.listen(port.client, () => {
console.log(`Listening at http://localhost:${port.client}/`);
});