FULL AI ANALYSIS

Tailwind JIT utilities missing in SvelteKit production build when class names use runtime template literals

Generated Oct 26, 2026, 9:23:15 AM

Analysis summary

Tailwind's JIT/content scanner performs static analysis of source files to collect the class names to generate; runtime template literals (especially with variable segments) can't be determined statically and are therefore dropped from the production CSS unless explicitly safelisted. Svelte's preprocessor and Vite may transform templates before Tailwind scans them, further hiding the raw class strings. Minifiers/optimizers are less likely culprits when dev works and production CSS lacks classes.

Possible causes

Tailwind content extractor cannot statically detect class names inside runtime template literals, so JIT omits them at build time

90%

Svelte/Vite preprocessing transforms templates before Tailwind scans, hiding class text from the extractor

60%

Incorrect content globs in tailwind.config.js excluding some files

30%

CSS minifier or bundler post-processing removing unused rules incorrectly

20%

Suggested fixes

1

Diagnostic step 1

Replace runtime template literals with a mapping object of allowed class strings (e.g., const sizeClass = {sm:'text-sm', md:'text-md'}; class={sizeClass[size]}) or conditional class: directives in Svelte to make classes static.

2

Diagnostic step 2

Add an explicit safelist block in tailwind.config.js for the dynamic patterns you need (use specific lists or precise regexes) and rebuild to verify.

3

Diagnostic step 3

Configure Tailwind's content extractor to include preprocessed output if your build chain alters source before scanning, or adjust Svelte preprocess order so Tailwind sees raw templates.

4

Diagnostic step 4

As a temporary check, add concrete classes in markup to confirm the issue is purge-related, then remove after applying a safer long-term pattern.

5

Diagnostic step 5

Avoid relying on arbitrary runtime string concatenation for utility names; prefer bracket notation only when values are known at build time.