vue 项目配置: 局域网 ip 发布 - 手机可访问
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" },
注意: 一定要是局域网
--------小尾巴
________一个人欣赏-最后一朵颜色的消逝-忠诚于我的是·一颗叫做野的心.决不受人奴役.怒火中生的那一刻·终将结束...