关于vue.js:vue2x配置打包无需更改生产或测试环境地址

0、装置依赖cross-env
1、内部IP.js文件拿到ip
2、保障打包
config/index.js
引入IP.js
const ipFile = require(‘../build/ip’) 

module.exports/dev/host设置值为获取的ip
host: ipFile.getIp(),

package.json/”build”: “cross-env NODE_ENV=production env_config=prod node build/build.js”

3、保障本地开发
config/index.js
引入IP.js
module.exports–dev–proxyTable上面的对象的target–写上开发的后端地址

const os = require(‘os’) 
module.exports = {
  getIp(){
    const ifaces = os.networkInterfaces() // 取得网络接口列表。
    let ip = ”
    for(const dev in ifaces) {
      ifaces[dev].forEach(function(details) {
        if(ip === ” && details.family === ‘IPv4’ && !details.internal) {
          ip = details.address
          return
        }
      })
    }
    console.log(ip,”ip——-“)
    return ip || ‘0.0.0.0’
  }
}

【腾讯云】轻量 2核2G4M,首年65元

阿里云限时活动-云数据库 RDS MySQL  1核2G配置 1.88/月 速抢

本文由乐趣区整理发布,转载请注明出处,谢谢。

您可能还喜欢...

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据