- 新增 .env 文件,配置 VUE_APP_PROXY_TARGET(开发模式代理目标)和 VUE_APP_API_BASE(接口根路径) - vue.config.js 的 devServer proxy 目标改用 VUE_APP_PROXY_TARGET 环境变量 - src/utils/http.ts 的 axios 实例配置 baseURL 为 VUE_APP_API_BASE,所有请求自动加前缀 - 所有页面中 http 接口调用去掉 /api/v2 前缀,由 axios baseURL 自动补全 - 文件上传的 el-upload action 属性改用动态绑定,引用 VUE_APP_API_BASE 环境变量 - 涉及文件:Login.vue、Home.vue、Article.vue、Hitokoto.vue、Music.vue、PhotoWall.vue、SourceImage.vue、Statistics.vue、SystemUser.vue、SystemConfig.vue、SystemConfigAdd.vue、SystemRole.vue Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
const path = require('path')
|
||
const AutoImport = require('unplugin-auto-import/webpack')
|
||
const Components = require('unplugin-vue-components/webpack')
|
||
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
|
||
const { defineConfig } = require('@vue/cli-service')
|
||
const { DefinePlugin } = require('webpack')
|
||
const { execSync } = require('child_process')
|
||
|
||
const commitInfo = execSync('git show -s --format=%cs(%h)').toString().trim()
|
||
|
||
module.exports = defineConfig({
|
||
publicPath: './',
|
||
transpileDependencies: true,
|
||
productionSourceMap: false,
|
||
configureWebpack: {
|
||
resolve: {
|
||
alias: { '@': path.resolve(__dirname, './src') }
|
||
},
|
||
plugins: [
|
||
AutoImport({
|
||
resolvers: [ElementPlusResolver()],
|
||
}),
|
||
Components({
|
||
resolvers: [ElementPlusResolver()],
|
||
}),
|
||
new DefinePlugin({
|
||
'process.env.VERSION': `'${commitInfo}'`
|
||
})
|
||
]
|
||
},
|
||
chainWebpack: config => {
|
||
// fork-ts-checker-webpack-plugin v6 与 TypeScript 5 不兼容(无法覆写只读的 performance.mark)
|
||
// 类型检查改由 tsc --noEmit 承担
|
||
config.plugins.delete('fork-ts-checker')
|
||
},
|
||
devServer: {
|
||
port: 8080,
|
||
proxy: {
|
||
'^/api': {
|
||
target: process.env.VUE_APP_PROXY_TARGET,
|
||
changeOrigin: true
|
||
}
|
||
}
|
||
}
|
||
})
|