-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
45 lines (40 loc) · 1.18 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
const webpack = require('webpack');
const path = require('path');
const express = require('express');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const compression = require('compression');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackDevConfig = require('./webpack/webpack.dev');
const router = express.Router();
const app = express();
app.use(compression());
app.use(bodyParser.json());
app.use(cookieParser());
app.use(express.static('dist'));
app.use('/', router);
if (process.env.NODE_ENV === 'development') {
/**
* Hot reload
* https://github.com/webpack/webpack-dev-middleware
*/
const compiler = webpack(webpackDevConfig);
app.use(
webpackDevMiddleware(compiler, {
// webpack-dev-middleware options
publicPath: webpackDevConfig.output.publicPath
})
);
} else {
router.get('/', function(req, res) {
res.sendFile('index.html', { root: path.resolve(__dirname, 'dist') });
});
}
const port = 8080;
app.listen(port, err => {
if (err) {
throw err;
}
console.log(`> Running with ${process.env.NODE_ENV} mode`);
console.log(`> Ready on http://localhost:${port}`);
});