-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
48 lines (38 loc) · 1.07 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
import express from 'express';
import path from 'path';
import open from 'open';
import bodyParser from 'body-parser';
var dev = process.env.NODE_ENV !== 'production';
if (dev) {
var webpackDevMiddleware = require('webpack-dev-middleware');
var webpackHotMiddleware = require('webpack-hot-middleware');
var webpack = require('webpack');
var config = require('../webpack.config');
}
const port = 3000;
const app = express();
app.listen(port, function(error) {
if (error) {
console.log(error);
} else {
open(`http://localhost:${port}`);
}
});
if (dev) {
const compiler = webpack(config);
app.use(
webpackDevMiddleware(compiler, {
hot: true,
noInfo: true,
publicPath: config.output.publicPath
})
);
app.use(webpackHotMiddleware(compiler));
}
app.use(bodyParser.json());
//static files
app.use(express.static(path.resolve(__dirname, '../public')));
//all other requests
app.get('/*', function(req, res) {
res.sendFile(path.join(__dirname, '../public/index.html'));
});