buster/apps/web/vite.config.ts

84 lines
2.6 KiB
TypeScript
Raw Normal View History

2025-08-13 03:21:24 +08:00
import tailwindcss from '@tailwindcss/vite';
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
import viteReact from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
2025-08-13 04:07:06 +08:00
import checker from 'vite-plugin-checker';
2025-08-13 03:21:24 +08:00
import viteTsConfigPaths from 'vite-tsconfig-paths';
2025-08-12 11:28:36 +08:00
2025-09-04 01:36:20 +08:00
const config = defineConfig(({ command, mode }) => {
2025-08-15 01:59:13 +08:00
const isBuild = command === 'build';
2025-09-06 07:31:24 +08:00
const isProduction = mode === 'production' || mode === 'staging';
const isTypecheck = process.argv.includes('--typecheck') || process.env.TYPECHECK === 'true';
const useChecker = !process.env.VITEST && isBuild;
2025-09-09 06:19:19 +08:00
const isLocalBuild = process.argv.includes('--local') || mode === 'development';
const target = isLocalBuild ? ('bun' as const) : ('cloudflare-module' as const);
2025-08-15 01:59:13 +08:00
return {
server: { port: 3000 },
plugins: [
// this is the plugin that enables path aliases
viteTsConfigPaths({ projects: ['./tsconfig.json'] }),
tailwindcss(),
2025-09-03 04:42:43 +08:00
tanstackStart({
customViteReactPlugin: true,
2025-09-09 06:19:19 +08:00
target,
2025-09-03 04:42:43 +08:00
}),
2025-08-15 01:59:13 +08:00
viteReact(),
2025-09-03 04:37:52 +08:00
useChecker
? checker({
typescript: isTypecheck,
biome: isProduction,
})
: undefined,
2025-08-15 01:59:13 +08:00
],
2025-09-04 05:36:46 +08:00
worker: {
format: 'es',
},
2025-09-03 04:37:52 +08:00
build: {
2025-09-06 07:31:24 +08:00
chunkSizeWarningLimit: 1250,
minify: isProduction ? 'esbuild' : false,
reportCompressedSize: false, // Disable gzip size reporting to speed up build
2025-09-03 04:37:52 +08:00
rollupOptions: {
// Exclude test and stories files from build
external: (id) => {
// Exclude .test and .stories files
if (/\.(test|stories)\.(js|ts|jsx|tsx)$/.test(id)) {
return true;
}
// Don't externalize React and React DOM - let them be bundled
return false;
},
output: {
manualChunks(id) {
if (id.includes('node_modules/lodash')) {
return 'vendor-lodash';
}
if (id.includes('node_modules/lodash-es')) {
return 'vendor-lodash';
}
// // Move supabase modules to their own chunk
if (id.includes('node_modules/@supabase')) {
return 'vendor-supabase';
}
if (id.includes('zod')) {
return 'vendor-zod';
}
if (id.includes('@tanstack')) {
return 'vendor-tanstack';
}
},
},
2025-09-06 07:31:24 +08:00
// Optimize tree-shaking for CloudFlare
treeshake: {
moduleSideEffects: false,
propertyReadSideEffects: false,
tryCatchDeoptimization: false,
},
2025-09-03 04:37:52 +08:00
},
},
2025-08-15 01:59:13 +08:00
};
2025-08-12 11:28:36 +08:00
});
export default config;