-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
38 lines (31 loc) · 1.12 KB
/
server.js
File metadata and controls
38 lines (31 loc) · 1.12 KB
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
const path = require('path');
const child_process = require('child_process');
const jsonServer = require('json-mock-kuitos');
const serverConfig = require('./server-config');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const webpackConfigration = require('./webpack-dev.config');
const compiler = webpack(webpackConfigration);
const app = jsonServer.create();
// 配置开发环境及热启动
app.use(webpackDevMiddleware(compiler, {
noInfo: true,
publicPath: webpackConfigration.output.publicPath
}));
app.use(webpackHotMiddleware(compiler, {
log: console.log,
path: '/__webpack_hmr',
heartbeat: 10 * 1000
}));
app.use(jsonServer.defaults({ static: path.resolve(__dirname) }));
// API 是否使用mock
app.use(serverConfig.apiPrefix, jsonServer.proxy(serverConfig.apiUri, serverConfig.apiPort));
app.listen(serverConfig.serverPort, err => {
if (err) {
console.log(err);
return;
}
const url = `http://127.0.0.1:${serverConfig.serverPort}/fake-portal/index.html`;
console.log(`Listening at ${url}`);
});