获取本地方法
const os = require('os')
exports.getIp = () => {
const [, WLAN] = Object.values(os.networkInterfaces())
for (let i = 0; i < WLAN.length; i++) {
const { family, address, internal } = WLAN[i];
if (family === 'IPv4' && address !== '127.0.0.1' && !internal) return address
}
}
webpack.config.js 设置ip
/**
* @type {import('webpack').Configuration}
*/
module.exports = {
//...
devServer: {
host: getIp(),
//...
},
//...
}