Skip to content

Conversation

@chenjiahan
Copy link
Member

@chenjiahan chenjiahan commented Jan 25, 2026

Summary

  • Convert the built‑in JS rule to a oneOf structure: js-raw for ?raw imports and js-transform for SWC/Babel transforms.
  • Add new oneOf IDs (CHAIN_ID.ONE_OF.JS_RAW, CHAIN_ID.ONE_OF.JS_TRANSFORM)
  • Update plugins (Babel/Svelte/SVGR) to attach to the transform branch.

Benefits

  • Raw handling now shares the same default rule scope (e.g. source.include/exclude)
  • The rule layout matches standard Rspackpatterns
  • The oneOf split is easier to understand and customize.

Breaking change

Existing chain customizations that attach loaders directly to CHAIN_ID.RULE.JS must move to oneOf.

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings January 25, 2026 01:41
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @chenjiahan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the internal JavaScript rule processing by implementing a oneOf structure. This change aims to improve the modularity and clarity of how different types of JavaScript files are handled within the build system. By explicitly separating raw asset imports from transformable JavaScript code, it provides a more robust and extensible foundation for future customizations and ensures consistent application of rules across various plugins.

Highlights

  • Refactored JavaScript Rule Structure: The built-in JavaScript rule has been converted to a oneOf structure, clearly separating js-raw for ?raw imports (treated as asset/source) and js-transform for SWC/Babel transformations (treated as javascript/auto).
  • New Chain IDs for OneOf Branches: New CHAIN_ID.ONE_OF identifiers, JS_RAW and JS_TRANSFORM, have been introduced to support this new rule organization, allowing for more granular control and customization.
  • Plugin Adaptations: Existing plugins such as Babel, Svelte, and SVGR have been updated to correctly attach their loaders and configurations to the new js-transform branch, ensuring compatibility with the refactored rule system.
  • Breaking Change Notification: This change introduces a breaking change for any custom configurations that directly modify CHAIN_ID.RULE.JS, requiring them to adapt to the new oneOf structure.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the built-in JavaScript rule to use a oneOf structure, separating raw imports from SWC/Babel transforms. This is a solid architectural improvement that aligns with standard Rspack/webpack patterns and enhances configuration clarity. The changes are consistently applied across various plugins that interact with the JS rule. My review focuses on improving the robustness of these plugins by adding defensive checks to prevent potential runtime errors if the expected configuration structure isn't present.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the built-in JavaScript rule structure to use a oneOf pattern, splitting JS file handling into two branches: js-raw for ?raw imports and js-transform for SWC/Babel transformations. This change provides better consistency with Rspack patterns and makes the rule structure easier to understand and customize.

Changes:

  • Converted the JavaScript rule from using separate rules (CHAIN_ID.RULE.JS and CHAIN_ID.RULE.JS_RAW) to a single rule with two oneOf branches (CHAIN_ID.ONE_OF.JS_RAW and CHAIN_ID.ONE_OF.JS_TRANSFORM)
  • Updated all plugins (Babel, Svelte, SVGR) to correctly access loaders through the new JS_TRANSFORM oneOf branch
  • Updated test snapshots to reflect the new webpack config structure with oneOf hierarchy

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/core/src/configChain.ts Added new oneOf identifiers JS_RAW and JS_TRANSFORM
packages/core/src/plugins/swc.ts Restructured JS rule to use oneOf pattern instead of separate rules
packages/plugin-babel/src/plugin.ts Updated to access babel loader through JS_TRANSFORM oneOf
packages/plugin-svelte/src/index.ts Updated to access SWC loader through JS_TRANSFORM oneOf
packages/plugin-svgr/src/index.ts Updated to access SWC/Babel loaders through JS_TRANSFORM oneOf
packages//tests/snapshots/.snap Updated test snapshots to reflect new oneOf structure

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cloudflare-workers-and-pages
Copy link

Deploying rsbuild with  Cloudflare Pages  Cloudflare Pages

Latest commit: be91b81
Status: ✅  Deploy successful!
Preview URL: https://7a80f295.rsbuild-v2.pages.dev
Branch Preview URL: https://js-rule-oneof-0125.rsbuild-v2.pages.dev

View logs

@chenjiahan chenjiahan merged commit c3c2510 into main Jan 25, 2026
6 checks passed
@chenjiahan chenjiahan deleted the js_rule_oneOf_0125 branch January 25, 2026 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant