Skip to content

Having trouble getting Tailwind to discover and bundle classes that are included dynamically from the database in sveltekit. #12750

Answered by alex-krasikau
Jorenm asked this question in Help
Discussion options

You must be logged in to vote

Hello @Jorenm!

Tailwind CSS operates at the build stage, scanning files specified in the content section and generating the final CSS based on the classes encountered during this file scan.

In short, if Tailwind enters /src/index.ts and encounters a class name in any form, it will be included in the generated CSS:

// /src/index.ts

// 1.
<div class="mt-4">...</div>

// 2.
// mt-4

// 3.
const offsetByType = {
  "sm": "mt-2",
  "md": "mt-4",
  "lg": "mt-8",
}

Any of the above combinations will result in Tailwind adding the following style to the resulting CSS:

.mt-4 {
  margin-top: 1rem;
}

Tailwind does not analyse compiled files, run code, or read actual webpage content— it only scans f…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@Jorenm
Comment options

Answer selected by Jorenm
Comment options

You must be logged in to vote
1 reply
@geantas
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants