-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (30 loc) · 961 Bytes
/
index.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
const express = require('express');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const expressStaticGzip = require('express-static-gzip');
const webpackConfig = require('./config/webpack/webpack.dev.config');
const compiler = webpack(webpackConfig);
const app = express();
switch (process.env.NODE_ENV) {
case 'development':
app.use(webpackDevMiddleware(compiler, {
publicPath: webpackConfig.output.publicPath,
stats: { colors: true },
logLevel: 'warn',
}));
app.use(webpackHotMiddleware(compiler, {
path: '/__webpack_hmr',
}));
app.use(express.static(`${__dirname}/build`));
break;
case 'production':
app.use(expressStaticGzip(`${__dirname}/build`, {
enableBrotli: true,
}));
break;
default:
break;
}
const PORT = process.env.PORT || 3000;
app.listen(PORT);