staven630 / vue-cli4-config

vue-cli4配置vue.config.js持续更新

Home Page:https://staven630.github.io/vue-cli4-config/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

请问在vue.config.js如何获取config.plugin('define')定义的变量?

luchanan opened this issue · comments

config.plugin('define').tap(args => {
      args[0] = {
        ...args[0],
        "APPVERSION": 'fefefef'
      }
      return args
    })

在vue.config.js使用会报错

ReferenceError: APPVERSION is not defined

但是在index.html却可以

window.appVersion = '<%=APPVERSION%>'

是不是vue.config.js不是这么使用呢?

vue.config.js里定义个全局变存放APPVERSION就可以在vue.config.js里访问。config.plugin('define')定义的是process.env上的变量,在.env文件里定义VUE_APP_APPVERSION就能达到效果。