Compiler

Compile cn, clsx, and twMerge templates while preserving their semantics.

Import from twl/macro and configure the bundler plugin.

InputOutput
cn`p-2 p-4` "p-4"
clsx`p-2 p-4` "p-2 p-4"
twMerge`p-2 p-4` "p-4"
cn`p-2 ${value}` __twl_cn("p-2", value)
clsx`p-2 ${value}` __twl_clsx("p-2", value)
twMerge`p-2 ${value}` __twl_twMerge("p-2", value)

Comments and static whitespace are removed at build time. Interpolations become ordinary arguments to the matching function. Ordinary function calls are redirected to twl/runtime. Unused macro imports are removed, so no runtime import from twl/macro remains.

Diagnostics

The compiler rejects namespace imports, bindings that shadow a macro import, and interpolations inside comments. Each diagnostic includes a file and line.

Options

OptionDefaultPurpose
from['twl/macro']Modules exposing the macro API, including custom re-export modules.
include/\.[cm]?[jt]sx?$/Files to compile. Next.js uses its own loader rule.
exclude/node_modules/Skip dependencies.

twl/macro contains type declarations only and requires compilation. Use twl directly for runtime template support.

On this page