1. Create a new .env.test file in the root directory
content:
NODE_ENV = 'test'
Second, configure the baseurl file
let baseUrl= ""; //这里是一个默认的url,可以没有
switch (process.env.NODE_ENV) {
case 'development':
baseUrl = "http://localhost:8080/dcxt/shop/" //开发环境url
break
case 'test': // 需要和自己配置的环境名字对应起来
baseUrl = "https://www.baidu.com/dcxt/shop/" //测试环境中的url
break
case 'production':
baseUrl = "https://www.baidu.com/dcxt/shop/" //生产环境url
break
}
export default baseUrl;
Three, configure in the axios file
Fourth, modify the configuration of package.json
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test": "vue-cli-service build --mode test",
"lint": "vue-cli-service lint"
},
In this way, the package typed out by executing npm run test is the package of the test environment