-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·53 lines (43 loc) · 1.16 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
46
47
48
49
50
51
52
53
'use strict';
const path = require('path');
const express = require('express');
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const port = 3000;
const NODE_ENV = process.env.NODE_ENV || 'development';
const config = require(`./webpack.${NODE_ENV}.config.js`);
const isDevMode = NODE_ENV !== 'production';
const app = express();
if (isDevMode) {
const compiler = webpack(config);
const middleware = new WebpackDevServer(compiler, {
publicPath: '/',
contentBase: '/',
stats: {
colors: true,
hash: false,
timings: true,
chunks: false,
chunkModules: false,
modules: false
},
quiet: false,
noInfo: false,
watchOptions: {
poll: true
}
});
middleware.listen(port);
} else {
app.use(express.static(path.join(__dirname, 'dist')));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
app.listen(port, (error) => {
if (error) {
console.error(error);
} else {
console.info('==> Production: 🌎 Listening on port %s. Open up ' + 'http://localhost:%s/ in your browser.', port, port);
}
});
}