Init applications
This commit is contained in:
59
apps/cat-admin-web/vite.config.ts
Normal file
59
apps/cat-admin-web/vite.config.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
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,
|
||||
},
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user