不支持

vue启动时自动获取本地ip

'use strict';

const devEnv = require('./dev.env');
const path = require('path');


const os = require('os');
///获取本机ip///
function getIPAdress() {
var interfaces = 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;
}
}
}
}
const myHost = getIPAdress();

module.exports = {
dev: {
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/': {
target: devEnv.API_ROOT,
changeOrigin: true,
pathRewrite: {
// '^/': '/weixin/api/'
}
}
},
// host: 'localhost',
host: myHost,//浏览器访问局域网ip地址http://192.168.1.xxx:8081
port: 8080,
autoOpenBrowser: true,
errorOverlay: true,
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

useEslint: false,
showEslintErrorsInOverlay: false,


devtool: 'cheap-module-eval-source-map',
cacheBusting: true,
cssSourceMap: true
},
build: {
index: path.resolve(__dirname, '../dist/index.html'),
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: './',
productionSourceMap: false,
productionGzip: false,
productionGzipExtensions: ['js', 'css'],
bundleAnalyzerReport: process.env.npm_config_report
}
};

 

 替换config文件夹中index,js

 

 

 允许局域网访问你的ip和端口

打开防火墙>高级设置>入站规则>新建规则>选择端口>所有本地端口>允许链接>下一步>命名>完成

posted @ 2022-09-07 17:18  骑上我的小摩托  阅读(1687)  评论(0编辑  收藏  举报