1. Modify the env.production file
# just a flag
ENV = 'production'
# base api
VUE_APP_SERVICE_URL = 'https://****.****.***'
# VUE_APP_BASE_API = '/api' 反向代理就加这个
2. Modify the env.development file
# just a flag
ENV = 'development'
# base api
# VUE_APP_SERVICE_URL = 'https://****.***.***'
# VUE_APP_BASE_API = '/api'
3. Modify the vue.config.js file
module.exports = {
publicPath: '/',//如果发现访问不了改成./
outputDir: 'dist',//文件目录
assetsDir: 'static',
lintOnSave: process.env.NODE_ENV === 'production',//development开发 production生产
productionSourceMap: false,//打包时不生成.Map,应为.Map文件是出错时会解析在哪里哪行出错,不安全
devServer: {
port: port,
host: 'localhost',//主机
open: true,
// https:true,
overlay: {
warnings: false,
errors: true
},
/**
* 动态代理
**/
proxy: {
[process.env.VUE_APP_BASE_API]: {
target: process.env.VUE_APP_SERVICE_URL,
changeOrigin: false,
pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: ''
}
}
}
// before: require('./mock/mock-server.js')
},
}
Package production environment
npm run build:prod
I use tp so I put it in the /public folder, create a /backend folder, and put all the packaged things in it
Visit https://***.***.com/backend/
If it is separated from the front and back, niginx is needed as a reverse proxy. I didn’t find a lot of them here.