-
Notifications
You must be signed in to change notification settings - Fork 11
feat(): new option: oneOfRulesForBabel #4804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Walkthrough在构建配置中,将针对 JS/TS 的 babel-loader 规则改为一组 oneOf 规则,并新增可选配置项 oneOfRulesForBabel 以在 babel-loader 之前插入额外规则。类型声明文件同步新增该配置项的定义,其余现有字段与行为保持不变。 Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. 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 |
There was a problem hiding this 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 introduces a new configuration option oneOfRulesForBabel that allows users to specify custom webpack rules that will be processed before the default Babel rule for TypeScript/JavaScript files.
- Adds a new
oneOfRulesForBabelconfiguration option to the webpack configuration - Wraps the existing Babel loader configuration in a
oneOfarray structure - Enables custom rule injection before the default Babel processing
Comments suppressed due to low confidence (1)
packages/build-next-bricks/src/build.js:1
- The new
oneOfRulesForBabelconfiguration option lacks documentation. Consider adding a comment explaining its purpose, expected format, and how it interacts with the default Babel rule to help maintainers understand this feature.
import path from "node:path";
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
next-core
|
||||||||||||||||||||||||||||
| Project |
next-core
|
| Branch Review |
steve/v3-build
|
| Run status |
|
| Run duration | 00m 25s |
| Commit |
|
| Committer | Shenwei Wang |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
17
|
| View all changes introduced in this branch ↗︎ | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
packages/build-next-bricks/index.d.ts (1)
91-94: 为 oneOfRulesForBabel 增补语义说明,避免误用类型声明本身没问题,但建议用注释明确:
- 这是插入到 JS/TS 处理链的 oneOf 组“前面进行匹配”的扩展点;
- oneOf 语义为“命中后不再继续匹配后续规则”,若想“前置处理后仍使用 babel”,需在自定义规则的 use 链中自行包含 babel-loader。
可直接在类型上方添加 JSDoc:
moduleRules?: RuleSetRule[]; + /** + * 在 JS/TS oneOf 规则中优先匹配的自定义规则列表。 + * 注意:该组为 oneOf,命中后不会再执行后续的 babel-loader。 + * 如需“前置并继续 babel”,请在自定义 rule 的 use 链中显式包含 "babel-loader"。 + */ oneOfRulesForBabel?: RuleSetRule[];packages/build-next-bricks/src/build.js (2)
361-371: 为外层 oneOf 增加 test 限定,缩小匹配范围并降低意外覆盖风险目前外层规则无 test,会让所有资源进入该 oneOf 尝试匹配。建议仅限 JS/TS,以避免对图片/字体等后续规则造成潜在覆盖与无谓的正则测试。
- { - oneOf: [ + { + test: /\.[tj]sx?$/, + oneOf: [ ...(config.oneOfRulesForBabel ?? []), { - test: /\.[tj]sx?$/, loader: "babel-loader", exclude: /node_modules|\.d\.ts$/, options: { rootMode: "upward", }, }, ], },说明:
- 内层 Babel 子规则保留/去掉 test 均可;保留更直观,双层 test 不冲突。
361-371: 补充用法示例与最小验证用例为减少误解,建议:
- 在文档中给出两种示例:
- “替代 Babel”的 oneOf 自定义规则示例;
- “前置+继续 Babel”的自定义规则(use 链包含 babel-loader)示例。
- 增加一个生成 webpack 配置的单测,断言:
- 当 oneOfRulesForBabel 为空时,最终 oneOf 末项为 babel-loader;
- 当提供匹配不到的规则时,仍落到 babel-loader;
- 当提供匹配到的规则时,不再匹配 babel-loader(或示例中包含了 babel-loader)。
我可以帮忙起草示例与测试骨架。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge base: Disabled due to data retention organization setting
📒 Files selected for processing (2)
packages/build-next-bricks/index.d.ts(1 hunks)packages/build-next-bricks/src/build.js(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build (20.x)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
packages/build-next-bricks/src/build.js (1)
361-371: 确认oneOf规则是否按预期:自定义规则是替代还是在执行完毕后继续走 Babel?
- 当前实现将
config.oneOfRulesForBabel放在首位,若其中规则匹配.ts/.tsx/.js,后续的babel-loader将被跳过——这是“替代”而非“前置+继续”。- 若目标是允许替代(如切换到 swc/ts-loader),无需调整;
- 若目标是“前置处理后仍需执行 Babel”,需在文档中说明:在自定义规则中合并
babel-loader或改用支持叠加的方案(如enforce: 'pre'或嵌套规则)。建议在 README/CHANGELOG 中强调此行为并提供使用示例。
依赖检查
组件之间的依赖声明,是微服务组件架构下的重要信息,请确保其正确性。
请勾选以下两组选项其中之一:
或者:
提交信息检查
Git 提交信息将决定包的版本发布及自动生成的 CHANGELOG,请检查工作内容与提交信息是否相符,并在以下每组选项中都依次确认。
破坏性变更:
feat作为提交类型。BREAKING CHANGE: 你的变更说明。新特性:
feat作为提交类型。问题修复:
fix作为提交类型。杂项工作:
即所有对下游使用者无任何影响、且没有必要显示在 CHANGELOG 中的改动,例如修改注释、测试用例、开发文档等:
chore,docs,test等作为提交类型。Summary by CodeRabbit