[POC] feat(core): support experimental Rspack builtin CSS - #8101
[POC] feat(core): support experimental Rspack builtin CSS#8101intellild wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughAdds a top-level 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@codex review |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/core/src/plugins/css.ts`:
- Around line 257-265: Update isBuiltinCssEnabled in the core CSS plugin and the
corresponding builtin-CSS checks in the Less and Sass plugins to inspect the
finalized Rspack configuration rather than config.tools.rspack directly. Resolve
array and callback-based ToolsRspackConfig forms before reading experiments.css,
and preserve native CSS handling so css-loader/extract loaders are not installed
when the final config enables builtin CSS.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6c3a5786-10f4-4ab2-8735-30b04db40c5c
📒 Files selected for processing (8)
packages/core/src/loader/cssUrlLoader.tspackages/core/src/plugins/css.tspackages/core/src/types/config.tspackages/core/tests/css.test.tspackages/plugin-less/src/index.tspackages/plugin-less/tests/index.test.tspackages/plugin-sass/src/index.tspackages/plugin-sass/tests/index.test.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c1bdea49e8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8bd1db7e25
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7fd3536f87
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7fd3536f87
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2c87092eb8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cb2a65a9db
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ce4405c4e1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5982dcb06c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eb83dd426b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9847eccc39
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
e6316ae to
a72a04b
Compare
a72a04b to
4020e3f
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4020e3f2eb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| .parser({ | ||
| exportType: 'text', | ||
| namedExports: true, | ||
| }) |
There was a problem hiding this comment.
Merge native parser options into inline CSS rule
When experiments.css is enabled and a user configures native parser options via tools.css.parser (for example url: false, import: false, or resolveImport), this rule-level parser object overrides the module.parser['css/auto'] options that applyBuiltinCssConfig just merged. As a result, import './style.css?inline' still resolves url()/@import using Rspack defaults instead of the user's built-in CSS parser settings; merge config.tools.css?.parser into this inline parser and then force exportType: 'text'.
Useful? React with 👍 / 👎.
| * Only takes effect when `experiments.css` is enabled. | ||
| * @experimental | ||
| */ | ||
| export interface ToolsCSSConfig { |
There was a problem hiding this comment.
Rspack's builtin CSS support is not a "tool", we should avoid providing a tools.* config for builtin CSS
There was a problem hiding this comment.
I’d prefer to keep this PR focused on the core changes and exclude any plugin-related changes.
| expect(mainRule).toBeTruthy(); | ||
| expect(cssModulesRule).toBeTruthy(); | ||
| expect(urlRule).toBeUndefined(); | ||
| expect(inlineRule).toMatchObject({ | ||
| type: 'css/auto', | ||
| parser: { | ||
| exportType: 'text', | ||
| namedExports: true, | ||
| }, | ||
| }); | ||
| expect(inlineRule).not.toHaveProperty('generator'); | ||
| expect(loaders.some((loader) => loader.includes('css-loader/index'))).toBe(false); | ||
| expect(loaders.some((loader) => loader.includes('style-loader/index'))).toBe(false); | ||
| expect(loaders.some((loader) => loader.includes('cssExtractLoader'))).toBe(false); | ||
| expect(loaders).toContain('builtin:lightningcss-loader'); | ||
| expect(matchPlugin(rspackConfigs[0], 'CssExtractRspackPlugin')).toBeFalsy(); | ||
| expect(rspackConfigs[0].experiments?.css).toBe(true); | ||
| expect(rspackConfigs[0].module?.parser).toMatchObject({ | ||
| 'css/auto': { | ||
| import: false, | ||
| namedExports: true, | ||
| }, | ||
| }); | ||
| expect(rspackConfigs[0].module?.parser?.['css/auto']).not.toHaveProperty('url'); | ||
| expect(rspackConfigs[0].module?.generator).toMatchObject({ | ||
| 'css/auto': { | ||
| exportsConvention: 'dashes-only', | ||
| exportsOnly: false, | ||
| localIdentName: 'custom__[local]', | ||
| }, | ||
| }); |
|
|
||
| type BuiltinCssRuleType = 'css' | 'css/auto' | 'css/global' | 'css/module'; | ||
|
|
||
| const CSS_MODULE_REGEX = /\.module(s)?\.css$/i; |
There was a problem hiding this comment.
You can reuse the regex in packages/core/src/helpers/css.ts
| 'dashes-only', | ||
| ] as const; | ||
|
|
||
| const builtinCssExportConventionMap = Object.fromEntries( |
There was a problem hiding this comment.
Could we avoid computing this at the top level? Since it’s only used under certain conditions, initializing it eagerly adds unnecessary overhead
chenjiahan
left a comment
There was a problem hiding this comment.
Let’s avoid experiments.css: it conflicts with Rspack v1’s option and doesn’t clearly describe the Rsbuild behavior change.
Summary
This PR adds an experimental Rsbuild
experiments.cssoption for using Rspack's built-in CSS module types. When enabled, CSS, CSS Modules,?inline, Less, and Sass use the nativecss/*pipeline withoutcss-loader,style-loader, orCssExtractRspackPlugin; native parser and generator options can be set throughtools.css.Rsbuild needs a dedicated option because
tools.rspackcan be a sync or async callback and runs after Rsbuild creates its CSS rules. Readingtools.rspack.experiments.csstherefore cannot reliably select the internal CSS pipeline.CSS
?urlimports and Vue SFC CSS Modules are currently unsupported in this mode and emit warnings.by OpenAI Codex