vue项目区分开发、测试、生产环境

1、分别在根目录下新建三个文件.env.development,.env.production,.env.test,在文件中分别写入
NODE_ENV = “development”,NODE_ENV = “production”,NODE_ENV = “test”
2、修改package.json命令

"scripts": {
    "dev": "vue-cli-service serve --mode development",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint",
    "build-test": "vue-cli-service build --mode test",
    "build-production": "vue-cli-service build --mode production"
  },

3、在js文件中使用process.env.NODE_ENV来区分

你可能感兴趣的:(vue.js,javascript,前端)