Refactor Vite configuration for TanStack Start integration

- Updated the Vite configuration to use a function for dynamic settings based on the mode.
- Enhanced plugin management to conditionally include workspace packages and other plugins based on the test mode.
- Maintained existing server, build, and resolve settings while improving code readability and maintainability.

These changes streamline the Vite setup for TanStack Start, ensuring better adaptability for different environments.
This commit is contained in:
mantrakp04 2026-04-30 12:53:10 -07:00
parent d7f55c1ffd
commit 1e0e1df407

View File

@ -98,44 +98,52 @@ function waitForWorkspacePackages(packages: string[]): Plugin {
};
}
export default defineConfig({
server: {
port: Number(`${process.env.NEXT_PUBLIC_STACK_PORT_PREFIX || "81"}42`),
fs: {
allow: [stackAuthRootPath],
export default defineConfig(({ mode }) => {
const isVitest = mode === "test" || process.env.VITEST === "true";
return {
server: {
port: Number(`${process.env.NEXT_PUBLIC_STACK_PORT_PREFIX || "81"}42`),
fs: {
allow: [stackAuthRootPath],
},
},
},
build: {
rollupOptions: {
output: {
manualChunks(id) {
if (id.startsWith(tanstackStartSourceRoot)) {
return "stack-auth-sdk";
}
return undefined;
build: {
rollupOptions: {
output: {
manualChunks(id) {
if (id.startsWith(tanstackStartSourceRoot)) {
return "stack-auth-sdk";
}
return undefined;
},
},
},
},
},
resolve: {
dedupe: ["react", "react-dom"],
alias: {
"@stackframe/tanstack-start": tanstackStartSourcePath,
resolve: {
dedupe: ["react", "react-dom"],
alias: {
"@stackframe/tanstack-start": tanstackStartSourcePath,
},
},
},
ssr: {
noExternal: [/^@stackframe\//, /^@radix-ui\//],
},
optimizeDeps: {
include: ["@stackframe/stack-shared", "@stackframe/stack-shared/config"],
},
plugins: [
stackSdkSourceTransforms(),
waitForWorkspacePackages(["@stackframe/tanstack-start", "@stackframe/stack-shared", "@stackframe/stack-ui"]),
watchNodeModules(["@stackframe/tanstack-start", "@stackframe/stack-shared", "@stackframe/stack-ui"]),
tsConfigPaths(),
tanstackStart(),
nitro(),
viteReact(),
],
ssr: {
noExternal: [/^@stackframe\//, /^@radix-ui\//],
},
optimizeDeps: {
include: ["@stackframe/stack-shared", "@stackframe/stack-shared/config"],
},
plugins: [
stackSdkSourceTransforms(),
...(isVitest ? [] : [
waitForWorkspacePackages(["@stackframe/tanstack-start", "@stackframe/stack-shared", "@stackframe/stack-ui"]),
watchNodeModules(["@stackframe/tanstack-start", "@stackframe/stack-shared", "@stackframe/stack-ui"]),
]),
tsConfigPaths(),
...(isVitest ? [] : [
tanstackStart(),
nitro(),
]),
viteReact(),
],
};
});