-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack-dev-server.js
45 lines (39 loc) · 1.12 KB
/
webpack-dev-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
import React from 'react';
import ReactDOM from 'react-dom/server';
import path from 'path';
import Express from 'express';
import webpack from 'webpack';
import { port } from './src/config';
import webpackConfig from './webpack.dev.config';
import Html from './src/Html';
const devPort = (Number(port) + 1);
const compiler = webpack(webpackConfig);
const serverOptions = {
reload: true,
publicPath: webpackConfig.output.publicPath,
headers: { 'Access-Control-Allow-Origin': '*' },
stats: {
colors: true,
modules: true,
reasons: true,
errorDetails: true,
},
};
const app = new Express();
app.use(require('webpack-dev-middleware')(compiler, serverOptions));
app.use(Express.static(path.join(__dirname, 'static')));
app.get('*', (req, res) => {
const markup = (
`<!DOCTYPE html>
${ReactDOM.renderToString(<Html />)}`
);
res.send(markup);
});
app.listen(devPort, err => {
if (err) {
console.error(err);
} else {
// console.info('==> 🚧 Webpack development server listening on port %s', port);
console.info(`==> 🚧 Webpack development server listening on port ${devPort}`);
}
});