@stylexjs/postcss-plugin
Configuration options
babelConfig
babelConfig: object; // Default: {}Options for Babel configuration. By default, the plugin reads the
babel.config.js in your project. For custom configurations, set
babelrc: false and specify desired options. Refer to
Babel Config Options for available options.
Unless you explicitly provide babelConfig.cwd, the plugin uses its cwd
option as Babel's working directory to keep config resolution consistent.
cwd
cwd: string; // Default: process.cwd()Working directory for the plugin; defaults to process.cwd(). Dependency paths
and Babel config resolution use this value.
exclude
exclude: string[] // Default: []Array of paths or glob patterns to exclude from compilation. Paths in exclude
take precedence over include.
When include is omitted, the plugin automatically excludes common build and
dependency folders (for example node_modules, .next, dist, build).
importSources
importSources: Array<string | { from: string, as: string }>; // Default: ['@stylexjs/stylex', 'stylex']Possible strings where you can import stylex from. Files that do not match the import sources may be skipped from being processed to speed up compilation.
When omitted, the plugin infers importSources from your
@stylexjs/babel-plugin options (if present), while still keeping the default
StyleX sources.
Precedence order is:
- explicit PostCSS
importSources - inferred from Babel config
- built-in defaults
include
include: string[] // Default: auto-discoveredArray of paths or glob patterns to compile.
When omitted, the plugin auto-discovers source files under cwd and direct
dependencies that use StyleX (checking dependencies, peerDependencies, and
optionalDependencies).
useCSSLayers
useCSSLayers: boolean; // Default: falseEnabling this option switches Stylex from using :not(#\#) to using @layers
for handling CSS specificity.
Debugging auto-discovery
Set STYLEX_POSTCSS_DEBUG=1 to log the resolved importSources, final
include/exclude globs, and discovered dependency directories.