Files
72e6b69d68a84678b2cb63d416f…/apps/cat-admin-web/vite.config.ts
2025-12-11 16:35:43 +00:00

60 lines
2.1 KiB
TypeScript
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.

import path from "path";
import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react-swc";
import tailwindcss from "@tailwindcss/vite";
import nvwaVitePlugin from "@nvwa-app/vite-plugin";
import Pages from "vite-plugin-pages";
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
console.log("env", env);
// 检查是否启用调试构建模式(通过环境变量控制)
const isDebugBuild = env.NVWA_BUILD_DEBUG === "true" || process.env.NVWA_BUILD_DEBUG === "true";
return {
define: {
"import.meta.env.NVWA_BASE_URL": JSON.stringify(env.NVWA_BASE_URL),
"import.meta.env.NVWA_AUTH_REQUIRED": JSON.stringify(env.NVWA_AUTH_REQUIRED ?? "false"),
"import.meta.env.NVWA_AUTH_ENABLED": JSON.stringify(env.NVWA_AUTH_ENABLED ?? "true"),
},
server: {
port: Number(process.env.PORT) || 15713,
},
plugins: [
react(),
tailwindcss(),
nvwaVitePlugin(),
Pages({
dirs: ["src/pages"],
routeBlockLang: "json",
exclude: ["**/components/**", "**/lib/**", "**/custom/**"],
}),
],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
build: {
// 调试模式下禁用压缩和混淆,保持代码可读性
minify: isDebugBuild ? false : "esbuild",
// 生成 source maps 以便调试
sourcemap: isDebugBuild ? true : false,
// 保持代码分割,不合并成单个大文件
rollupOptions: {
output: {
// 调试模式下保持文件名的可读性(不使用 hash便于调试
entryFileNames: isDebugBuild ? "assets/[name].js" : "assets/[name]-[hash].js",
chunkFileNames: isDebugBuild ? "assets/[name].js" : "assets/[name]-[hash].js",
assetFileNames: isDebugBuild ? "assets/[name].[ext]" : "assets/[name]-[hash].[ext]",
},
},
// 调试模式下不压缩 CSS
cssMinify: !isDebugBuild,
// 增加 chunk 大小警告阈值(调试模式下可能文件较大)
chunkSizeWarningLimit: isDebugBuild ? 2000 : 500,
},
};
});