# @stylexjs/babel-plugin (/docs/api/configuration/babel-plugin) ## Configuration options ### `aliases` ```ts aliases: {[key: string]: string | Array} // Default: undefined ``` `aliases` option allows you to alias project directories to absolute paths, making it easier to import modules. Example: `'@/components/*': [path.join(__dirname, './src/components/*')]` *** ### `classNamePrefix` ```ts classNamePrefix: string; // Default: 'x' ``` Prefix to be applied to every generated className. *** ### `debug` ```ts debug: boolean; // Default: false ``` When `true`, StyleX will use debug class names and insert `data-style-src` props to help identify the source of the styles. *** ### `dev` ```ts dev: boolean; // Default: false ``` When `true`, StyleX will insert function calls to inject the CSS rules at runtime, making it possible to use StyleX without setting up CSS file extraction. *** ### `importSources` ```ts importSources: Array; // Default: ['@stylexjs/stylex'] ``` Override the package name where you can import stylex from. Used for setting up custom module aliases. Example: `importSources: ['stylex', { from: '@acme/ui', as: 'css' }]` *** ### `runtimeInjection` ```ts runtimeInjection: boolean; // Default: false ``` Should StyleX generate code to inject styles at runtime? This may be useful during development but should be disabled in production. *** ### `styleResolution` ```ts styleResolution: // Default: 'property-specificity' | 'application-order' | 'property-specificity' ``` Strategy to use for merging styles. * **application-order**: The last style applied wins. Consistent with how inline styles work on the web. * **property-specificity**: More specific styles will win over less specific styles. Consistent with React Native. (`margin-top` wins over `margin`) *** ### `test` ```ts test: boolean; // Default: false ``` When `true`, StyleX will only output debug classNames identifying the source of the styles. It will *not* generate any styles or functional classNames. This can be useful for snapshot testing. *** ### `env` ```ts env: { [key: string]: mixed }; // Default: {} ``` An object of compile-time constants and functions available as [`stylex.env`](/docs/api/javascript/env). Values are substituted before other StyleX APIs are compiled. Supports strings, numbers, objects, and functions. *** ### `treeshakeCompensation` ```ts treeshakeCompensation: boolean; // Default: false ``` Named imports of StyleX variables are unused after compilation. Some bundlers may remove them as dead code. Causing variables to be undefined. Enable this option to prevent that by adding an import with no specifier. (e.g. `import './my-vars.stylex.js'`) *** ### `unstable_moduleResolution` ```ts unstable_moduleResolution: // Default: undefined | { // The module system to be used. // Use this value when using `ESModules`. type: 'commonJS', // The absolute path to the root directory of your project. // Only used as a fallback rootDir?: string, // Override `.stylex.js` with your own extension. themeFileExtension?: string, } | { // Use this when using the Haste module system // Where all files are imported by filename rather // than relative paths and all filenames must be unique. type: 'haste', // Override `.stylex.js` with your own extension. themeFileExtension?: string, } ``` Strategy to use for resolving variables defined with `defineVars`. This is required if you plan to use StyleX's theming APIs. **NOTE**: While theming APIs are stable, the shape of this configuration option may change in the future. # @stylexjs/eslint-plugin (/docs/api/configuration/eslint-plugin) ## Configuration options ### `@stylexjs/valid-styles` rule ```ts type Options = { // Possible strings where you can import stylex from // // Default: ['stylex', '@stylexjs/stylex'] validImports: Array; // Custom limits for values of various properties propLimits?: PropLimits; // @deprecated // Allow At Rules and Pseudo Selectors outside of // style values. // // Default: false allowOuterPseudoAndMedia: boolean; // @deprecated // Disallow properties that are known to break // in 'legacy-expand-shorthands' style resolution mode. // // Default: false banPropsForLegacy: boolean; }; type PropLimits = { // The property name as a string or a glob pattern [propertyName: string]: { limit: // Disallow the property | null // Allow any string value | 'string' // Allow any number value | 'number' // Any string other 'string' or 'number' // will be considered to be a valid constant // e.g. 'red' or '100px'. | string // You can also provide numeric constants // e.g. 100 or 0.5 | number // You can also provide an array of valid // number or string constant values. | Array; // The error message to show when a value doesn't // conform to the provided restriction. reason: string; }; }; ``` #### Example ```json { "rules": { "@stylexjs/valid-styles": [ "error", { "propLimits": { "mask+([a-zA-Z])": { "limit": null, "reason": "Use the `mask` shorthand property instead." }, "fontSize": { "limit": "number", "reason": "Only numeric font values are allowed" }, "padding": { "limit": [0, 4, 8, 16, 32, 64], "reason": "Use a padding that conforms to the design system" } } } ] } } ``` ### `@stylexjs/sort-keys` rule ```ts type Options = { // Possible strings where you can import stylex from // // Default: ['stylex', '@stylexjs/stylex'] validImports: Array; // Minimum number of keys required after which the rule is enforced // // Default: 2 minKeys: number; // Sort groups of keys that have a blank line between them separately // // Default: false allowLineSeparatedGroups: boolean; }; ``` #### Example ```json { "rules": { "@stylexjs/valid-styles": "error", "@stylexjs/sort-keys": [ "warn", { "minKeys": 3, "allowLineSeparatedGroups": true } ] } } ``` ### `@stylexjs/valid-shorthands` rule ```ts type Options = { // Possible strings where you can import stylex from // // Default: ['stylex', '@stylexjs/stylex'] validImports: Array; // Whether `!important` is allowed // // Default: false allowImportant: boolean; // Whether the expansion uses logical direction properties over physical // // Default: false preferInline: boolean; }; ``` ### `@stylexjs/enforce-extension` rule ```ts type Options = { // Possible strings where you can import stylex from // // Default: ['stylex', '@stylexjs/stylex'] validImports: Array; // The file extension to enforce for theme files // // Default: '.stylex.js' themeFileExtension: string; }; ``` ### `@stylexjs/no-unused` rule ```ts type Options = { // Possible strings where you can import stylex from // // Default: ['stylex', '@stylexjs/stylex'] validImports: Array; }; ``` ### `@stylexjs/no-legacy-contextual-styles` rule ```ts type Options = { // Possible strings where you can import stylex from // // Default: ['stylex', '@stylexjs/stylex'] validImports: Array; }; ``` # @stylexjs/postcss-plugin (/docs/api/configuration/postcss-plugin) ## Configuration options ### babelConfig ```js 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](https://babeljs.io/docs/options) for available options. *** ### cwd ```js cwd: string; // Default: process.cwd() ``` Working directory for the plugin; defaults to `process.cwd()`. *** ### exclude ```js exclude: string[] // Default: [] ``` Array of paths or glob patterns to exclude from compilation. Paths in `exclude` take precedence over `include`. *** ### importSources ```js importSources: Array; // 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. *** ### include ```js include: string[] // Required ``` Array of paths or glob patterns to compile. *** ### useCSSLayers ```js useCSSLayers: boolean; // Default: false ``` Enabling this option switches Stylex from using `:not(#\#)` to using `@layers` for handling CSS specificity. # @stylexjs/unplugin (/docs/api/configuration/unplugin) Universal bundler plugin for StyleX built on top of [`unplugin`](https://github.com/unjs/unplugin). It compiles StyleX modules, aggregates the generated CSS, and appends the result to an emitted CSS asset (or creates `stylex.css` as a fallback). Adapters are available for Vite/Rollup, Webpack/Rspack, and esbuild. ## Install ## Usage by bundler ### Vite ```ts title="vite.config.ts" import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import stylex from '@stylexjs/unplugin'; export default defineConfig({ plugins: [stylex.vite({ useCSSLayers: true }), react()], }); ``` * Keep `stylex.vite()` before framework plugins to preserve Fast Refresh. * Provide a CSS entry so Vite emits an asset for the plugin to append to. * Dev virtual modules: * `/virtual:stylex.css` — aggregated CSS endpoint. * `virtual:stylex:runtime` — JS runtime for hot CSS reloads. * `virtual:stylex:css-only` — JS shim that only triggers CSS reloads. Add `` and either a `