-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.dev.ts
46 lines (43 loc) · 1.31 KB
/
webpack.dev.ts
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
import os from 'os';
import merge from 'webpack-merge';
import FriendlyErrorsWebpackPlugin from 'friendly-errors-webpack-plugin';
import common, { BUILD_RESOURCE_NAME, isWindows, PUBLIC_PATH } from './webpack.common';
import { exportPort } from './src/config';
// Network
const ips = os.networkInterfaces();
const availableIpv4 = Object.values(ips)
.map(item => item!.filter(addr => addr.family === 'IPv4' && !addr.internal)) // 只输出外网地址
.reduce((acc, item) => acc.concat(item), [])
.map(item => item.address);
const devServer = {
disableHostCheck: true,
historyApiFallback: {
rewrites: [{ from: new RegExp(`^${PUBLIC_PATH}(?!${BUILD_RESOURCE_NAME})`), to: PUBLIC_PATH }],
},
hot: true,
compress: true,
quiet: true,
overlay: true,
host: isWindows ? availableIpv4[0] || '127.0.0.1' : '0.0.0.0',
port: 8001,
proxy: {
[`${PUBLIC_PATH}api`]: {
target: `http://0.0.0.0:${exportPort}`,
secure: false,
changeOrigin: true,
},
},
};
export default merge(common, {
mode: 'development',
devtool: 'cheap-module-eval-source-map',
devServer,
plugins: [
new FriendlyErrorsWebpackPlugin({
compilationSuccessInfo: {
messages: [`Server is running: http://${availableIpv4[0]}:${devServer.port}${PUBLIC_PATH}`],
},
clearConsole: true,
}),
],
});