feat: [BREAKING] [v0.3] Allow writing styles inside pug's style(lang='styl') tag; move to new react-pug compilation pipeline and linting (fully TS-compatible)#4
Conversation
…with support for 'style' tags and full TSX support
…ich don't have pug
style(lang='styl') tag; move to new react-pug compilation pipeline and linting (fully TS-compatible)
style(lang='styl') tag; move to new react-pug compilation pipeline and linting (fully TS-compatible)style(lang='styl') tag; move to new react-pug compilation pipeline and linting (fully TS-compatible)
style(lang='styl') tag; move to new react-pug compilation pipeline and linting (fully TS-compatible)style(lang='styl') tag; move to new react-pug compilation pipeline and linting (fully TS-compatible)
style(lang='styl') tag; move to new react-pug compilation pipeline and linting (fully TS-compatible)style(lang='styl') tag; move to new react-pug compilation pipeline and linting (fully TS-compatible)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upgrade 0.2 to 0.3
cssxjsin yourpackage.jsonto^0.3eslint-plugin-cssxjsand any directly installed@cssxjs/*packages to^0.3eslint@^9and the new flateslint.config.mjsconfigPug TypeScript and Embedded Styles
CSSX 0.3 uses the new
react-pugtransform.This migration guide focuses on moving Pug components to the new preferred style and updating ESLint.
Quick Migration Checklist
cssxjsand CSSX-related packages to^0.3.cssxjs/babelin your Babel presets.stylorcsstemplate strings into a terminalstyleblock inside thepugtemplate.style(lang='styl')for Stylus andstylefor plain CSS.tsc --noEmitwithnpx cssxjs checkfor Pug-aware project type checks.eslint-plugin-cssxjs.Embedded Style Blocks
Old
Pug structure and styles were usually split between
pugand a separatestyltemplate:New
Put local styles at the end of the
pugtemplate:Result: the component structure and its local styles stay in one Pug block. CSSX moves the style block into a local
styltemplate during the Babel transform.For plain CSS:
Behavior:
styleblock must be the last top-level node in thepugtemplate.styledefaults to CSS.style(lang='styl')uses Stylus.stylandcsstemplate literals still work for JSX components and shared module-level styles.TypeScript in Pug
Pug templates in
.tsxfiles 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 checkfor Pug-aware type checks:Do not rely on
tsc --noEmitalone for Pug components. TypeScript treats the content ofpug`...`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-cssxjsthrough legacy ESLint config:New
Use ESLint v9 and
eslint-plugin-cssxjswith flat config:Important:
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-tsxfor TypeScript-aware Pug editing and embedded style highlighting.For Stylus highlighting inside
style(lang='styl'), also install a Stylus language extension.Validation
After migrating:
npx eslint .Then run your app build or bundler so Babel processes the new embedded style blocks.