Upgrade 0.2 to 0.3
- Change
cssxjsin yourpackage.jsonto^0.3 - Change
eslint-plugin-cssxjsand any directly installed@cssxjs/*packages to^0.3 - If you lint Pug templates, use
eslint@^9and the new flateslint.config.mjsconfig - Run your package manager install command after the version bump
Pug TypeScript and Embedded Styles
CSSX 0.3 uses the new react-pug transform.
This migration guide focuses on moving Pug components to the new preferred style and updating ESLint.
Quick Migration Checklist
- Upgrade
cssxjsand CSSX-related packages to^0.3. - Keep
cssxjs/babelin your Babel presets. - Move local styles in Pug components from separate
stylorcsstemplate strings into a terminalstyleblock inside thepugtemplate. - Use
style(lang='styl')for Stylus andstylefor plain CSS. - Remove TypeScript workarounds around Pug templates; TS expressions are now supported directly in TSX files.
- Replace
tsc --noEmitwithnpx cssxjs checkfor Pug-aware project type checks. - Replace the old CSSX ESLint preset with
eslint-plugin-cssxjs. - Use ESLint v9 flat config. Do not upgrade to ESLint v10 for this setup.
Embedded Style Blocks
Old
Pug structure and styles were usually split between pug and a separate styl template:
New
Put local styles at the end of the pug template:
Result: the component structure and its local styles stay in one Pug block. CSSX moves the style block into a local styl template during the Babel transform.
For plain CSS:
Behavior:
- The embedded
styleblock must be the last top-level node in thepugtemplate. styledefaults to CSS.style(lang='styl')uses Stylus.- Standalone
stylandcsstemplate literals still work for JSX components and shared module-level styles.
TypeScript in Pug
Pug templates in .tsx files now support TypeScript expressions. If you previously extracted typed expressions out of Pug only to satisfy the old transform or editor tooling, you can usually move them back into the template.
Use npx cssxjs check for Pug-aware type checks:
Do not rely on tsc --noEmit alone for Pug components. TypeScript treats the content of pug`...` as template string text, so it does not parse or type-check Pug expressions by itself.
See TypeScript Support for the full guide and command options.
ESLint Migration (Breaking)
Old
Projects commonly used the old CSSX ESLint preset or eslint-config-cssxjs through legacy ESLint config:
New
Use ESLint v9 and eslint-plugin-cssxjs with flat config:
Important:
- Use ESLint v9 for CSSX 0.3 Pug linting.
- Do not use ESLint v10 for this setup.
- The plugin processor maps JavaScript and TypeScript diagnostics from inside
pugtemplates back to the original Pug source.
ESLint with neostandard
If your project uses neostandard, compose the CSSX processor after the base config:
VS Code
Install vscode-react-pug-tsx for TypeScript-aware Pug editing and embedded style highlighting.
For Stylus highlighting inside style(lang='styl'), also install a Stylus language extension.
Validation
After migrating:
Then run your app build or bundler so Babel processes the new embedded style blocks.