webpack 打包

在vue项目中的config/index 配置了host为localhost 只能通过localhost或者127.0.0.1访问,不能通过IP访问,把localhost改为0.0.0.0 可以正常通过IP访问,但是启动项目时会默认打开0.0.0.0:8080

要如何修改才能默认打开正常使用localhost,并且可以通过IP访问

webpack 打包


回答:

const os = require("os");

/**

* 获取当前机器的ip地址

*/

function getIpAddress() {

var interfaces = os.networkInterfaces();

for (var dev in interfaces) {

let iface = interfaces[dev];

for (let i = 0; i < iface.length; i++) {

let { family, address, internal } = iface[i];

if (family === "IPv4" && address !== "127.0.0.1" && !internal) {

return address;

}

}

}

}

然后通过webpack配置来实现

以上是 webpack 打包 的全部内容, 来源链接: utcz.com/p/937583.html

回到顶部