forked from Tencent/vConsole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.serve.config.js
45 lines (43 loc) · 1.21 KB
/
webpack.serve.config.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
const path = require('path');
const fs = require('fs');
const webpack = require('webpack');
const { merge } = require('webpack-merge');
const baseConfig = require('./webpack.config.js');
const contentBase = path.join(__dirname, '/');
module.exports = merge(baseConfig, {
mode: 'development',
devtool: 'eval-source-map',
devServer: {
host: '0.0.0.0',
port: 9191,
disableHostCheck: true,
contentBase: contentBase,
openPage: 'dev/index.html',
historyApiFallback: true,
noInfo: true,
overlay: true,
open: true,
hot: true,
inline: true,
before(app) {
app.all('*', (req, res) => {
const delay = req.query.t || Math.ceil(Math.random() * 100);
setTimeout(() => {
res.status(req.query.s || 200);
const filePath = path.join(contentBase, req.path);
try {
fs.accessSync(filePath, fs.constants.F_OK);
// res.send(fs.readFileSync(filePath));
res.sendFile(filePath);
} catch (e) {
res.end();
}
// console.log(req.query);
}, delay);
});
}
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
});