Fix style config resolution during SSR

This commit is contained in:
Jordan Pittman 2024-12-02 15:58:48 -05:00
parent 89f291c007
commit 8e3cdc3531

View file

@ -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,