blog-admin-web/vue.config.js
灌糖包子 86c7d75963
feat: 引入环境变量配置,统一管理接口路径
- 新增 .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>
2026-04-01 15:21:39 +08:00

46 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}
}
}
})