-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
28 lines (25 loc) · 871 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
const express = require('express');
const webpack = require('webpack');
const path = require('path');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const history = require('connect-history-api-fallback');
const config = require('./webpack/webpack.dev');
const port = 3001;
const app = express();
if (process.env.ENV === 'development') {
const compiler = webpack(config);
app.use(history());
app.use(webpackDevMiddleware(compiler, {
publicPath: config.output.publicPath,
}));
app.use(webpackHotMiddleware(compiler));
} else {
app.use(express.static(path.join(__dirname, 'dist')));
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist', 'index.html'));
});
}
app.listen(port, () => {
console.log(`Example app listening on port ${port}!\n`);
});