1.Vue3 配置开发-测试环境
1、根目录新建.env.testing、.env.donline文件
2、package.json=》scripts中配置
"start": "vue-cli-service serve --mode testing",
"start-o": "vue-cli-service serve --mode donline"
3、vue.config.js
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
let apiProxyTarget = process.env.VUE_APP_PROXY_URL // '192.168.254.43'
let devHost = process.env.VUE_APP_HOST
/**
* 是否分析 webpack 打包细节,以便于性能优化。
*/
let isAnalyzeBundle = false
/**
* 是否使用测试环境配置
*/
let isUseDevServerProxy = true
/**
* 基础编译配置。
* 更多配置项,请参考:https://cli.vuejs.org/config/
*/
let options = {
devServer: {}
}
//是否使用测试环境配置
// 解析 ajax proxy.
if (isUseDevServerProxy) {
let pathRewrite = {}
let devProxyOptions = {
'/cloudatlas-api': {
target: apiProxyTarget,
changeOrigin: true,
pathRewrite,
bypass: function (req, res, proxyOpt) {
res.set('RAD-PROXY', 'on');
res.set('RAD-PROXY-BY', apiProxyTarget);
}
}
}
options['devServer'] = options['devServer'] || {}
options['devServer']['proxy'] = devProxyOptions
options['devServer']['host'] = devHost
options['devServer']['port'] = 8081
}
//是否分析 webpack 打包细节,以便于性能优化。
if (isAnalyzeBundle) {
options['configureWebpack'] = options['configureWebpack'] || {}
options['configureWebpack']['plugins'] = options['configureWebpack']['plugins'] || []
options['configureWebpack']['plugins'].push(new BundleAnalyzerPlugin())
}
module.exports = options