forked from looknd/vue-willtable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
devServer.js
46 lines (43 loc) · 1.35 KB
/
devServer.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
46
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
const devWebpackConfig = require('./webpack.dev.conf');
const config = require('../config');
const options = {
publicPath: config.dev.assetsPublicPath,
clientLogLevel: 'warning',
contentBase: false,
historyApiFallback: true,
hot: true,
host: '0.0.0.0',
inline: true,
compress: true,
overlay: { warnings: false, errors: true },
quiet: true,
watchOptions: {
ignored: [/node_modules/],
poll: true,
},
};
const getIPAddress = () => {
const interfaces = require('os').networkInterfaces();
for (const devName in interfaces) {
for (const alias of interfaces[devName]) {
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
return alias.address;
}
}
}
return '';
};
(() => {
const pkgConfig = require('../package.json');
const IP = getIPAddress();
devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
compilationSuccessInfo: {
messages: [`${pkgConfig.name} 运行地址: http://${IP}:${config.dev.port}`],
},
}));
WebpackDevServer.addDevServerEntrypoints(devWebpackConfig, options);
new WebpackDevServer(webpack(devWebpackConfig), options).listen(config.dev.port, '0.0.0.0', () => { });
})();