forked from ElemeFE/smart-gesture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
33 lines (27 loc) · 768 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
const express = require('express');
const webpack = require('webpack');
const config = require('./webpack.dev.config.js');
const compiler = webpack(config);
const path = require('path');
const app = express();
app.use(require('webpack-dev-middleware')(compiler, {
publicPath: config.output.publicPath,
stats: {
colors: true,
chunks: false,
},
}));
app.use(require('webpack-hot-middleware')(compiler));
app.use(express.static(config.output.path));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'index.html'));
});
const server = app.listen(8000, (err) => {
if (err) {
console.log(err);
return false;
}
const port = server.address().port;
console.log(`Listening at http://localhost:${port}`);
return true;
});