-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (34 loc) · 964 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
37
38
39
40
41
const path = require('path');
const express = require('express');
const app = express();
const mode = process.env.NODE_ENV;
const port = 7000;
if (mode === 'development') {
const morgan = require('morgan');
const webpack = require('webpack');
const config = require('./webpack/webpack.dev.conf.js');
const compiler = webpack(config);
// compiler.run((err, stats) => {
// console.log(stats.toString('minimal'));
// });
//
app.use(morgan('dev'));
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
app.use(require('webpack-hot-middleware')(compiler));
}
if (mode === 'production') {
app.use(express.static('dist'));
}
app.get('/', (req, res) => {
res.sendFile(path.join(path.join(__dirname, '/src/index.html')));
});
app.listen(port, (err) => {
if (err) {
console.log(err);
return;
}
console.log(`Server started at: http://localhost:${port}`);
});