-
Notifications
You must be signed in to change notification settings - Fork 4.9k
fix(taro-runtime): 修复 dom-external 代码被treeshaking #17584
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
此次更改将多个包的 `package.json` 文件中的版本号统一从 `4.0.12` 更新为 `4.0.13-alpha.0`。其中,`@tarojs/runtime` 包的 `sideEffects` 字段由空数组改为包含 `"./dist/dom-external/index.js"`,标记该文件具有副作用,影响打包工具的 tree-shaking 优化。其余包仅更新了版本号,未修改其他元数据或导出声明。
## Changes
| 文件/路径 | 变更摘要 |
|-----------------------------------------------|--------------------------------------------------|
| packages/taro-runtime/package.json | 版本号更新至 `4.0.13-alpha.0`,`sideEffects` 字段由空数组改为包含 `"./dist/dom-external/index.js"` |
| crates/native_binding/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| npm/darwin-arm64/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| npm/darwin-x64/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| npm/linux-x64-gnu/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| npm/linux-x64-musl/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| npm/win32-x64-msvc/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| packages/babel-plugin-transform-*-package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| packages/babel-preset-taro/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| packages/create-app/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| packages/css-to-react-native/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| packages/eslint-config-taro/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| packages/jest-helper/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| packages/postcss-*-package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| packages/rollup-plugin-copy/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| packages/shared/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| packages/stylelint-*-package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| packages/taro-*/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| packages/taro-framework-*/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| packages/taro-plugin-*/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| packages/taro-components-*/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| packages/taro-rn-*/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| packages/taro-webpack5-*/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
| packages/taroize/package.json | 版本号更新至 `4.0.13-alpha.0`,无其他改动 |
## Suggested reviewers
- tutuxxx
- luckyadam
## Poem
> 🐇
> 轻点脚步动一行,
> 副作用文件加标明。
> 打包工具细分明,
> 优化流程更清清。
> 小兔挥笔记新程,
> 代码世界又一春!📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (75)
✅ Files skipped from review due to trivial changes (74)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (7)
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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: 1
🧹 Nitpick comments (1)
packages/taro-runtime/package.json (1)
15-17: 建议使用通配符扩展副作用目录
当前仅指定了单个文件,如果 dom-external 目录下还包含其他副作用文件(如子模块或样式文件),建议使用 glob 通配符标记整个目录:- "sideEffects": [ - "./dist/dom-external/index.js" - ], + "sideEffects": [ + "./dist/dom-external/**/*.js" + ],这样可以确保目录下的所有 JavaScript 文件都不会被 tree-shaking 剔除。
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/taro-runtime/package.json(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
- GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-musl
- GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
- GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
- GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
- GitHub Check: Build Rust WASM / stable - wasm32-wasi
- GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
- GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
🔇 Additional comments (1)
packages/taro-runtime/package.json (1)
15-17: 已正确修复dom-external被 Tree-Shaking 移除的问题
将sideEffects从空数组修改为包含./dist/dom-external/index.js可阻止该模块被剔除,满足 PR 目标。
| "sideEffects": [ | ||
| "./dist/dom-external/index.js" | ||
| ], |
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.
💡 Verification agent
❓ Verification inconclusive
确认副作用文件路径正确性
请确保在构建产物中存在 dist/dom-external/index.js,以便 webpack 等打包工具在 tree-shaking 时保留该文件。
🏁 Script executed:
#!/bin/bash
# 验证构建产物中是否包含 dom-external/index.js
if [ ! -f dist/dom-external/index.js ]; then
echo "缺少 dist/dom-external/index.js,sideEffects 配置可能无效" >&2
exit 1
else
echo "dist/dom-external/index.js 存在"
fiLength of output: 159
修复:确保 sideEffects 指定的文件存在
在 packages/taro-runtime/package.json 中配置了:
"sideEffects": [
"./dist/dom-external/index.js"
]但经验证,构建产物中缺少 dist/dom-external/index.js,会导致 webpack 等工具在 tree‑shaking 时错误地移除此模块。
请在以下两点中选一并执行:
- 若该模块仍需保留,补充或修正构建脚本,确保最终产物中生成
packages/taro-runtime/dist/dom-external/index.js。 - 若该文件已废弃,删除或更新
sideEffects中对应的路径。
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #17584 +/- ##
========================================
Coverage 58.37% 58.37%
========================================
Files 469 469
Lines 27230 27230
Branches 5752 5953 +201
========================================
Hits 15895 15895
+ Misses 9962 9939 -23
- Partials 1373 1396 +23
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
这个 PR 做了什么? (简要描述所做更改)
dom-external index.js 里的代码被treeshaking,导致
dangerouslySetInnerHTML不能正常工作。这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台:
Summary by CodeRabbit