From 8e3cdc353152cb842509d6aa6ccc6434cb8077bd Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Mon, 2 Dec 2024 15:58:48 -0500 Subject: [PATCH] Fix `style` config resolution during SSR --- packages/@tailwindcss-vite/src/index.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/@tailwindcss-vite/src/index.ts b/packages/@tailwindcss-vite/src/index.ts index 9c92699fa..26acfdb6a 100644 --- a/packages/@tailwindcss-vite/src/index.ts +++ b/packages/@tailwindcss-vite/src/index.ts @@ -42,15 +42,31 @@ export default function tailwindcss(): Plugin[] { conditions: ['style', 'development|production'], tryIndex: false, preferRelative: true, + + // If the `ssr.resolve.conditions` config option is set it overrides the + // `conditions` option above when building for SSR. As a result, we may + // resolve to JS files instead of CSS files. To work around this we use + // `ssrConfig` to ensure correct behavior during SSR. + // + // This workaround is for Vite 5.x. Vite 6.x works correctly without + // this setting but keeping it around does not break anything. + ssrConfig: { + resolve: { + conditions: ['style', 'development|production'], + }, + }, }) + function customCssResolver(id: string, base: string) { return cssResolver(id, base, false, isSSR) } let jsResolver = config!.createResolver(config!.resolve) + function customJsResolver(id: string, base: string) { return jsResolver(id, base, true, isSSR) } + return new Root( id, () => moduleGraphCandidates,