1. 修改 /build/webpack.dev.conf.js
-
/*********************/ var os = require(‘os‘), ip = ‘‘, ifaces = os.networkInterfaces() // 获取本机ip function getMyIp () { for (var i in ifaces) { for (var j in ifaces[i]) { var val = ifaces[i][j] if (val.family === ‘IPv4‘ && val.address !== ‘127.0.0.1‘) { ip = val.address return } } } } getMyIp () /*********************/ ... ... ... ... compilationSuccessInfo: { messages: [ `: Application is running here: http://${devWebpackConfig.devServer.host}:${port} \n And here: http://${ip}:${port}` ], },
2. 修改 package.json
-
"scripts": { "dev": "webpack-dev-server --host 0.0.0.0 --inline --progress --config build/webpack.dev.conf.js", "start": "npm run dev", "lint": "eslint --ext .js,.vue src", "build": "node build/build.js" },
注意: 一定要是局域网