vue-cli 3.x 配置打包環境

重新建項目到設置打包環境

publicPath1.vue create vue-cli-env 建立應用
2.新建 vue.config.js 文件(vue cli 3 配置文件),設置
module.exports = {
  publicPath: './'
}
3.新建各個環境的文件,例如:.env.development .env.test .env.production4.在 package.json 文件中設置打包命令 --mode test 指的是當前選擇環境 test,即 .env.test 文件所表明環境
"scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "build:test": "vue-cli-service build --mode test",
    "lint": "vue-cli-service lint"
  },
 

關於環境變量的注意事項(.env.xx 文件)

* 環境名應該與環境文件統一 * 環境文件放置項目根目錄下 * 除了 baseUrl 和 NODE_ENV 其餘環境變量使用 VUE_APP 開頭

gitlab地址:https://github.com/lankongmoxing/vue-cli-3.0.3-build-env
相關文章
相關標籤/搜索