Introducing a new way to review your PRs.

Read the announcement

chakra-ui / panda

🐼 Universal, Type-Safe, CSS-in-JS Framework for Design Systems ⚡️

View on GitHub

19 documents · Updated Sep 23, 2026

docs / node-and-postcss-integration

Node and PostCSS integration

The Node and PostCSS packages expose Panda CSS to build tools in two ways. The Node package gives programs direct control of config loading, source analysis, CSS generation, and file output. The PostCSS package brings the same compiler work into a stylesheet pipeline.

Integration surfaces

Node package

@pandacss/node is the programmatic entry point for compiler work in a Node.js process. It lets another tool load a Panda config, create a compiler context, generate code and CSS, inspect source files, and respond to changes without going through the command line.

The package uses the Node runtime for file access, path handling, glob matching, and file watching. Its public surface includes complete generation as well as lower-level context and builder objects for tools that need to control when setup, extraction, or output occurs.

References: packages/…/index.ts• L1-15 packages/…/config.ts• L7-33 packages/…/node-runtime.ts• L10-81

PostCSS package

@pandacss/postcss is a PostCSS plugin that connects a stylesheet build to Panda's compiler. A PostCSS host gives the plugin a CSS root and source file. The plugin checks whether the file and root belong to Panda, then adds the CSS that the compiler derives from the project.

The plugin accepts a config path, working directory, log file, and an allow rule for files that would otherwise be skipped. It also reports source and config dependencies through PostCSS messages so the host can rebuild when Panda inputs change.

References: packages/…/index.ts• L1-15 packages/…/index.ts• L27-63 packages/…/index.ts• L84-96

Package relationship

The PostCSS package is a thin integration layer over the Node package. This keeps compiler behavior in the shared Node context while the PostCSS layer owns the rules for entering and leaving a stylesheet pipeline.

The command-line package exposes the PostCSS integration as @pandacss/dev/postcss. This gives projects a user-facing entry point while the package-level integration remains reusable by other PostCSS hosts.

References: packages/…/index.ts• L1-8 packages/…/postcss.js• L1-3 packages/…/package.json• L24-34

Compiler execution

Shared compiler context

Both integration surfaces build a PandaContext. The context joins the loaded config with the source project, parser, CSS generator, output service, and change tracking. This is the shared point at which project inputs become generated artifacts and stylesheet output.

The context uses the Node runtime to find and read configured source files. It can then parse those files, create the Panda stylesheet, and write the result to the configured output area. The direct Node flow writes output as a build result, while the PostCSS flow uses the same context to add output to the current CSS root.

The diagram shows how both entry points reach the same compiler context before they produce their different forms of output.

flowchart LR
  A[Node program] --> C[Load config and create Panda context]
  B[PostCSS host] --> D[Panda PostCSS plugin]
  D --> C
  C --> E[Read and parse project sources]
  E --> F[Generate Panda artifacts and CSS]
  F --> G[Write generated files]
  F --> H[Append CSS to PostCSS root]

References: packages/…/config.ts• L11-33 packages/…/create-context.ts• L13-46 packages/…/create-context.ts• L85-117 packages/…/index.ts• L33-56

Programmatic generation

The Node generation flow is for a tool that owns the build step. It loads the config, runs code generation, builds the stylesheet from the configured source set, and writes the result. In watch mode it keeps the context active and rebuilds the affected output when config or source files change.

This surface is the right choice when the caller needs generated files such as the style system or a standalone stylesheet. It does not require a PostCSS host because the Node package owns the compiler run and its output.

References: packages/…/generate.ts• L7-24 packages/…/generate.ts• L26-73 packages/…/codegen.ts• L4-25

Stylesheet transformation

The PostCSS flow is for a build that already processes stylesheets. The plugin first ignores files that are not CSS and normally ignores files under node_modules. It then checks for Panda layer input, prepares the shared compiler, extracts changed project sources, registers dependencies, and appends generated Panda CSS to the root.

This flow lets a bundler or stylesheet tool keep ownership of the CSS pipeline. Panda supplies the compiler output and dependency signals without replacing the host's later PostCSS processing.

References: packages/…/index.ts• L33-63 packages/…/index.ts• L84-96 packages/…/builder.ts• L151-208

Change handling

Configuration and source changes

The Node context can watch both configured source files and config dependencies. A config change refreshes the context before rebuilding. A source change updates the project view and regenerates the stylesheet from the changed source set.

The PostCSS builder uses the same change model during repeated stylesheet runs. It tracks file metadata and config dependencies so a host can avoid treating an unchanged project as a new compiler input while still receiving new artifacts after a real change.

References: packages/…/create-context.ts• L175-217 packages/…/generate.ts• L30-72 packages/…/builder.ts• L52-95

Build sequencing

The PostCSS plugin uses one shared builder for its work. It sequences calls to that builder so parallel PostCSS requests do not create competing compiler setup or context changes.

This matters when a host processes several stylesheets at once. The integration keeps the compiler state ordered, then lets each stylesheet receive the CSS and dependency messages produced for its own request.

References: packages/…/index.ts• L21-25 packages/…/index.ts• L65-77 packages/…/postcss.test.ts• L94-119

Integration choice

The two surfaces share compiler behavior but serve different owners of the build flow:

SurfaceBuild ownerMain resultBest fit
Node packageThe calling Node programGenerated artifacts and stylesheet filesA custom build tool, script, or long-running watcher
PostCSS packageThe PostCSS hostPanda CSS appended to a stylesheet rootA bundler or CSS pipeline that already runs PostCSS

Use the Node package when the caller needs to control the full compiler lifecycle. Use the PostCSS package when Panda must participate in an existing stylesheet transform.

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the Node exports, the PostCSS dependency on Builder, and the CLI postcss export aligned. A package can build while an integration entry point no longer resolves.
  • Preserve the boundary between full file generation and CSS-root transformation. Changes to shared compiler output can affect both generated files and CSS appended by PostCSS.
  • Keep PostCSS dependency messages tied to the current source file. A host may use those messages to decide which stylesheet requests to rebuild.
  • Recheck serialized builder access when changing PostCSS request handling. Shared compiler state must remain ordered for concurrent stylesheet processing.

Important failure modes

TriggerConsequenceGuard
The PostCSS input is not a CSS file or has no valid Panda layer declarationThe plugin leaves the input unchangedUse a Panda stylesheet entry with the expected layer declaration
A stylesheet under node_modules is processed without an allow ruleThe plugin skips Panda processing for that fileAdd a matching allow rule only when that dependency must be processed
Config or source dependencies are not reported to the hostChanges can leave stale generated CSS in watch or incremental buildsKeep dependency registration enabled for the configured include paths and config files
Several PostCSS requests mutate the shared builder at the same timeCompiler setup or context refresh can race across requestsKeep the plugin's serialized builder guard around shared processing

Key files

FileWhy to read it
packages/…/index.tsShows the public programmatic Node surface.
packages/…/config.tsShows how config becomes the shared compiler context.
packages/…/create-context.tsShows how source discovery, parsing, CSS output, and watching meet in one context.
packages/…/generate.tsShows the complete generation and watch lifecycle.
packages/…/builder.tsShows the controlled build operations used by stylesheet integrations.
packages/…/index.tsShows how PostCSS requests enter the compiler and receive CSS and dependency messages.
packages/…/postcss.jsShows the user-facing CLI package bridge to the PostCSS plugin.