feat: 添加broswer-vendors配置和相关依赖导出#352
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (2)
Walkthrough新增浏览器供应商构建配置与对应源文件,将核心依赖(Vue、Vue Router、Pinia、Vue I18n、SFC 编译器、Lodash)挂载为 window 全局变量,并在主 Rspack 配置中新增 pc 与 mobile 的 vendor 构建;同时调整 lodash 的导入为具名导入。 Changes
Sequence Diagram(s)sequenceDiagram
participant RspackConfig as RspackConfig
participant VendorBuild as vendorConfig()
participant EntryFile as broswer-vendors.ts
participant SWCLoader as SWC Loader
participant FS as Filesystem (dist/${type})
RspackConfig->>VendorBuild: import vendorConfig(type)
VendorBuild->>EntryFile: set entry -> ../src/broswer-vendors.ts
VendorBuild->>SWCLoader: apply SWC rules for .ts/.js
EntryFile->>SWCLoader: transpile imports (Vue, Pinia, ...)
SWCLoader->>VendorBuild: bundled UMD module (LcapBrowserVendors)
VendorBuild->>FS: write broswer-vendors.js to dist/${type}
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
兔子之诗
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
Actionable comments posted: 3
🧹 Nitpick comments (2)
packages/vue3/src/broswer-vendors.ts (1)
1-1: 文件名拼写错误:"broswer" 应为 "browser"所有相关文件名中 "broswer" 都拼写错误,建议统一修正为 "browser-vendors"。
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/vue3/src/broswer-vendors.ts` at line 1, The file name packages/vue3/src/broswer-vendors.ts is misspelled; rename it to browser-vendors.ts and update every import/export that references "broswer-vendors" to the corrected "browser-vendors" (search for that exact identifier in imports, barrel/index files, build configs, and tests). Ensure any module aliases or tsconfig/webpack/rollup entries that reference the old filename are updated, and run the type checker/build to catch remaining path errors.packages/vue3/build/broswer-vendors.js (1)
29-44: JS loader 缺少env.targets配置TypeScript loader(Lines 45-60)配置了
env: { targets }以确保正确的浏览器兼容性转译,但 JavaScript loader 缺少相同配置。这可能导致依赖包中的 ES6+ 代码在目标浏览器中出现兼容性问题。♻️ 建议为 JS loader 添加 env.targets
{ test: /\.[mc]?js$/, type: 'javascript/auto', use: [ { loader: 'builtin:swc-loader', options: { jsc: { parser: { syntax: 'ecmascript', }, }, + env: { targets }, }, }, ], },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/vue3/build/broswer-vendors.js` around lines 29 - 44, The JS loader block (the rule with test: /\.[mc]?js$/ using loader 'builtin:swc-loader' and options.jsc.parser.syntax = 'ecmascript') is missing the same env.targets compatibility configuration used by the TypeScript loader; add an env: { targets } entry inside the swc-loader options (alongside options.jsc) mirroring the targets used in the TypeScript loader so that dependency JS is transpiled to the same browser targets and avoids ES6+ compatibility issues.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/vue3/build/broswer-vendors.js`:
- Around line 20-25: 配置中的 library.export: 'default' 与源文件 broswer-vendors.ts
不匹配(源文件无默认导出),导致全局变量 LcapBrowserVendors 为 undefined;修复可选两种方式:如果该包只依赖副作用(只需设置
window.* 全局变量),则在打包配置的 library 对象中移除 export 属性;如果需要暴露模块 API,则在源码
broswer-vendors.ts 中添加默认导出(export default ...)以匹配 library.export:
'default',并确保导出的值赋给期望的全局标识 LcapBrowserVendors。
In `@packages/vue3/source/src/hooks/datasource-utils.js`:
- Line 1: 当前在 packages/vue3/source/src/hooks/datasource-utils.js 中用的是主入口导入
import { isEqual } from 'lodash',这会导致 rspack 打包时无法 tree-shake
且增大产物体积;请将导入改为子路径导入以减小打包体积,例如把对 isEqual 的引用改为从 'lodash/isEqual' 导入(定位到使用 isEqual
的模块或函数并替换导入语句),确保其他地方没有再用主入口方式引用 lodash。
In `@packages/vue3/src/broswer-vendors.ts`:
- Around line 1-13: The module currently attaches libs to window (window.Vue,
window.VueRouter, window.Pinia, window.VueI18n, window.VueCompilerSFC,
window.Lodash) but does not provide a default export required by the UMD build;
add a default export (e.g. export default { Vue, VueRouter, Pinia, VueI18n,
VueCompilerSFC, Lodash } or export default LcapBrowserVendors) so the bundle can
expose the global correctly, and add TypeScript declarations for the window
properties (declare global { interface Window { Vue: typeof Vue; VueRouter:
typeof VueRouter; Pinia: typeof Pinia; VueI18n: typeof VueI18n; VueCompilerSFC:
typeof VueCompilerSFC; Lodash: typeof lodash } }) to avoid compile errors.
---
Nitpick comments:
In `@packages/vue3/build/broswer-vendors.js`:
- Around line 29-44: The JS loader block (the rule with test: /\.[mc]?js$/ using
loader 'builtin:swc-loader' and options.jsc.parser.syntax = 'ecmascript') is
missing the same env.targets compatibility configuration used by the TypeScript
loader; add an env: { targets } entry inside the swc-loader options (alongside
options.jsc) mirroring the targets used in the TypeScript loader so that
dependency JS is transpiled to the same browser targets and avoids ES6+
compatibility issues.
In `@packages/vue3/src/broswer-vendors.ts`:
- Line 1: The file name packages/vue3/src/broswer-vendors.ts is misspelled;
rename it to browser-vendors.ts and update every import/export that references
"broswer-vendors" to the corrected "browser-vendors" (search for that exact
identifier in imports, barrel/index files, build configs, and tests). Ensure any
module aliases or tsconfig/webpack/rollup entries that reference the old
filename are updated, and run the type checker/build to catch remaining path
errors.
🪄 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: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: e33712a7-283a-43e9-8641-28e8f8d18d78
📒 Files selected for processing (4)
packages/vue3/build/broswer-vendors.jspackages/vue3/build/rspack.config.jspackages/vue3/source/src/hooks/datasource-utils.jspackages/vue3/src/broswer-vendors.ts
Summary by CodeRabbit
新功能
优化