Skip to main content

compile()

Compile a CSS string containing Tailwind directives into optimized CSS output.

Parameters

string
required
The input CSS string containing Tailwind directives like @tailwind utilities, @theme, @variant, etc.
CompileOptions
Optional compilation options

Return Value

array
Array of source patterns discovered from @source directives.
Root
Root configuration extracted from source() parameters in @tailwind utilities.Can be:
  • null - No root specified
  • 'none' - Explicitly disabled via source(none)
  • { base: string; pattern: string } - Explicit pattern
Features
Bitmask of features detected in the CSS:
  • Features.AtApply - @apply was used
  • Features.AtImport - @import was used
  • Features.JsPluginCompat - @plugin or @config was used
  • Features.ThemeFunction - theme() function was used
  • Features.Utilities - @tailwind utilities was used
  • Features.Variants - @variant was used
  • Features.AtTheme - @theme was used
function
Function to generate CSS for a given set of candidates.
Returns the compiled CSS string. Automatically caches results - if the same candidates are provided, returns the cached output without recompilation.
function
Function to generate a source map for the compiled CSS.

Example Usage


compileAst()

Compile a pre-parsed AST instead of a CSS string. This is useful when you already have an AST from the CSS parser.

Parameters

AstNode[]
required
Array of AST nodes from the CSS parser.
CompileOptions
Same options as compile() function. See above for details.

Return Value

Returns the same structure as compile(), except the build() function returns AstNode[] instead of a string, and there is no buildSourceMap() function.
function
Function to generate an AST for a given set of candidates.
Returns an array of AST nodes that can be further processed or converted to CSS using toCss().

Example Usage


Types

CompileOptions

Polyfills Enum

Features Enum

DecodedSourceMap