vue run dev 报错npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! tod@1.0.0 dev: webpack-dev-server -
新接手一个项目vue run dev报错,如下:npm ERR! code ELIFECYCLEnpm ERR! errno 1npm ERR! todo@1.0.0 dev: webpack-dev-server --inline --progress --config build/webpack.dev.conf.js研究半天发现是端口问题修改方法:打开config文件夹下的index.js文
·
新接手一个项目vue run dev报错,如下:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! todo@1.0.0 dev: webpack-dev-server --inline --progress --config build/webpack.dev.conf.js
研究半天发现是端口问题
修改方法:
打开config文件夹下的index.js文件找到如下图这段代码:
// Various Dev Server settings
host:'192.168.1.1', // can be overwritten by process.env.HOST
port: 8102, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
host 修改为获取本机ip
封装好的的代码:
/*
获取本机ip
*/
function getIPAddress(){
var interfaces = require('os').networkInterfaces();
for(var devName in interfaces) {
var iface = interfaces[devName];
for(var i = 0; i<iface.length; i++) {
var alias = iface[i];
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
return alias.address;
}
}
}
}
引入 :
// Various Dev Server settings
host:getIPAddress(), // can be overwritten by process.env.HOST
port: 8102, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
保存然后 vue run dev 就可以啦! 还有问题可以咨询留言
更多推荐
已为社区贡献1条内容
所有评论(0)