2025-06-17 22:37:37 +08:00
|
|
|
|
import { defineConfig, loadEnv } from "vite";
|
|
|
|
|
|
import path from "path";
|
|
|
|
|
|
import plugins from "./.build/plugins";
|
|
|
|
|
|
|
2025-07-03 17:13:21 +08:00
|
|
|
|
|
2025-06-17 22:37:37 +08:00
|
|
|
|
// https://vite.dev/config/
|
|
|
|
|
|
export default defineConfig((cnf) => {
|
2025-07-03 17:13:21 +08:00
|
|
|
|
|
2025-06-17 22:37:37 +08:00
|
|
|
|
const { mode } = cnf;
|
|
|
|
|
|
const env = loadEnv(mode, process.cwd());
|
|
|
|
|
|
const { VITE_APP_ENV } = env;
|
|
|
|
|
|
return {
|
|
|
|
|
|
base: VITE_APP_ENV === "production" ? "/" : "/",
|
|
|
|
|
|
plugins: plugins(cnf),
|
|
|
|
|
|
resolve: {
|
|
|
|
|
|
alias: {
|
|
|
|
|
|
"@": path.resolve(__dirname, "./src"),
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
css: {
|
|
|
|
|
|
// css全局变量使用,@/styles/variable.scss文件
|
|
|
|
|
|
preprocessorOptions: {
|
|
|
|
|
|
scss: {
|
|
|
|
|
|
additionalData: '@use "@/styles/var.scss" as *;',
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2025-06-19 23:45:22 +08:00
|
|
|
|
|
|
|
|
|
|
server: {
|
2025-06-22 19:09:13 +08:00
|
|
|
|
port: 17001,
|
|
|
|
|
|
open: true,
|
2025-06-19 23:45:22 +08:00
|
|
|
|
proxy: {
|
2025-06-22 19:09:13 +08:00
|
|
|
|
[env.VITE_WEB_BASE_API]: {
|
|
|
|
|
|
target: env.VITE_API_URL,
|
|
|
|
|
|
changeOrigin: true,
|
|
|
|
|
|
rewrite: (path) => path.replace(`${[env.VITE_WEB_BASE_API]}`, ""),
|
|
|
|
|
|
|
|
|
|
|
|
//查看真实代理url
|
|
|
|
|
|
bypass(req, res, options) {
|
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
|
const proxyUrl = new URL(options.rewrite(req.url) || '',(options.target)as string)?.href || '';
|
|
|
|
|
|
req.headers['x-req-proxyUrl'] = proxyUrl
|
|
|
|
|
|
res.setHeader('x-res-proxyUrl',proxyUrl)
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
2025-06-19 23:45:22 +08:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2025-06-17 22:37:37 +08:00
|
|
|
|
};
|
|
|
|
|
|
});
|