-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
34 lines (26 loc) · 938 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 webpack = require("webpack");
const webpackHotMiddleware = require("webpack-hot-middleware");
const webpackDevMiddleware = require("webpack-dev-middleware");
const express = require("express");
const opn = require("opn");
const webpakcConfig = require("./webpack.config.dev");
const path = require("path");
webpakcConfig.entry.app.unshift("webpack-hot-middleware/client?noInfo=true&reload=true");
const app = express(),
PORT = 8888,
DIST_DIR = path.join(__dirname, 'dist'),
compiler = webpack(webpakcConfig);
let devMiddleware = webpackDevMiddleware(compiler, {
publicPath: webpakcConfig.output.publicPath,
quiet: false
})
let hotMiddleware = webpackHotMiddleware(compiler, {
heartbeat: 2000
})
app.use(devMiddleware);
app.use(hotMiddleware);
app.use(express.static(DIST_DIR));
app.listen(PORT, function () {
console.log('成功启动:localhost:' + PORT);
opn('http://127.0.0.1:' + PORT);
})