-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.server.js
More file actions
63 lines (55 loc) · 1.65 KB
/
webpack.server.js
File metadata and controls
63 lines (55 loc) · 1.65 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
*@author Create by zhoulujun.cn on 1/4/1910:30 AM
*@version 1.0.0
* webpack server 配置
*/
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const open = require('open');
const config = require('./webpack.config');
process.env.NODE_ENV='development';
config.mode = 'development';
config.devtool='cheap-module-eval-source-map';
config.plugins.push(
new webpack.HotModuleReplacementPlugin(),//热替换
new webpack.NoEmitOnErrorsPlugin(),//去除系统抛出的错误消息
);
const addressObj = {
ip: getLocalIPAdress(),
port: 11036
};
new WebpackDevServer(webpack(config), {
historyApiFallback: true,
hot: true,//热加载
hotOnly: true,
overlay: {
errors: true//webpack编译出现的错误是否会出现在网页中
},
compress: false,
proxy: {
'/api/*': {
target: 'https://zhoulujun.cn/api',//代理地址
secure: false
}
}
})
.listen(addressObj.port,addressObj.ip,function (error) {
error&&console.log(error);
let address=`http://${addressObj.ip}:${addressObj.port}`;
// let address=`http://localhost:13080`;
open(address);
console.log('listening at:'+address)
});
function getLocalIPAdress () {
var interfaces = require('os').networkInterfaces();
for (let devName in interfaces) {
let iface = interfaces[devName];
for (let i = 0; i < iface.length; i++) {
let alias = iface[i];
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
return alias.address;
}
}
}
return 'localhost';
}