vue开发和生产环境切换


项目根目录

新建

.env.development (开发环境)

/*  文件中的内容主要是对开发环境和生产环境的请求接口路径做修改  */
		NODE_ENV = 'development'
		VUE_APP_API_URL = '/api'

.env.production (生产环境)

NODE_ENV = 'development'
	VUE_APP_API_URL = 'http://'

axios

axios.defaults.baseURL = process.env.VUE_APP_API_URL,

环境切换

package.json

"scripts": {
    "serve": "vue-cli-service serve",
    "production-serve": "vue-cli-service serve --mode production",  //这个
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },

启动项目

yarn serve
or
yarn production-serve
or
yarn build


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM