1.配置package.json
主要看的是 "build:all": "vue-cli-service build && vue-cli-service build --mode test && vue-cli-service build --mode development",
"scripts": {"dev": "vue-cli-service serve","build:prod": "vue-cli-service build","build:test": "vue-cli-service build --mode test","build:all": "vue-cli-service build && vue-cli-service build --mode test && vue-cli-service build --mode development","build": "pkg src/server/admin_web_server.js -t node12-win-x64,node12-linux-x64 -o my-server","build:stage": "vue-cli-service build --mode staging","preview": "node build/index.js --preview","lint": "eslint --ext .js,.vue src","test:unit": "jest --clearCache && vue-cli-service test:unit","test:ci": "npm run lint && npm run test:unit","svgo": "svgo -f src/icons/svg --config=src/icons/svgo.yml"},
2.新增你需要的环境
.env.development
# just a flag ENV = 'development'
.env.production
# just a flag ENV = 'production'
.env.test
# just a flag ENV = 'test'
3.修改vue.config.js中的 outputDir
module.exports = { ...publicPath: '/',outputDir: 'dist-'+process.env.ENV,assetsDir: 'static',lintOnSave: false,productionSourceMap: false, ... }
outputDir 是打包后输出的目录;也可按照其他方式命名,每个环境不一样即可
4.打包
终端执行:npm run build:all
搞定