Skip to content

Conversation

Single-Dancer
Copy link
Collaborator

@Single-Dancer Single-Dancer commented Jun 30, 2025

这个 PR 做了什么? (简要描述所做更改)
编译为es5 vite runner 配置错误

这个 PR 是什么类型? (至少选择一个)

  • 错误修复 (Bugfix) issue: fix #
  • 新功能 (Feature)
  • 代码重构 (Refactor)
  • TypeScript 类型定义修改 (Types)
  • 文档修改 (Docs)
  • 代码风格更新 (Code style update)
  • 构建优化 (Chore)
  • 其他,请描述 (Other, please describe):

这个 PR 涉及以下平台:

  • 所有小程序
  • 微信小程序
  • 支付宝小程序
  • 百度小程序
  • 字节跳动小程序
  • QQ 轻应用
  • 京东小程序
  • 快应用平台(QuickApp)
  • Web 平台(H5)
  • 移动端(React-Native)
  • 鸿蒙(harmony)

Summary by CodeRabbit

  • 新功能

    • 当编译器为 Vite 时,模板项目会在开发依赖中自动添加 @tarojs/plugin-generator 插件。
  • 重构

    • 优化了配置文件的修改逻辑,根据不同编译器类型(Vite 或 Webpack5)分别处理配置和错误提示。
    • 简化了 package.json 中 browserslist 字段的结构,统一为生产环境目标数组。

Copy link

coderabbitai bot commented Jun 30, 2025

Walkthrough

本次变更主要针对 Taro 项目的 ES5 生成器插件,增加了对 Vite 编译器的支持。更新内容包括根据不同编译器类型分别修改配置文件、错误处理逻辑和依赖模板,并简化了 package.json 中 browserslist 字段的结构。

Changes

文件/路径 变更摘要
packages/taro-cli/templates/default/package.json.tmpl 根据编译器类型(Vite/webpack5)添加 @tarojs/plugin-generator 依赖
packages/taro-plugin-generator/src/generators/es5/config.ts 按编译器类型分别处理配置及错误,重构参数和错误生成逻辑
packages/taro-plugin-generator/src/generators/es5/index.ts 动态获取编译器类型,调整 updateConfig 调用,简化 browserslist 配置

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant es5Generator
    participant configUpdater

    User->>es5Generator: 执行 es5Generator(ctx)
    es5Generator->>es5Generator: 获取 compilerType
    es5Generator->>configUpdater: updateConfig({ ctx, compilerType })
    configUpdater->>configUpdater: 根据 compilerType 修改配置
    configUpdater-->>es5Generator: 返回
    es5Generator->>es5Generator: 更新 browserslist 配置
    es5Generator-->>User: 生成完成
Loading

Suggested reviewers

  • tutuxxx

Poem

在代码田野兔儿跳,
Vite、Webpack 都照料。
配置分明各自跑,
错误提示更可靠。
Browserslist 也瘦身,
新旧兼容乐逍遥!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d1d8b7d and 22cdcb5.

📒 Files selected for processing (3)
  • packages/taro-cli/templates/default/package.json.tmpl (1 hunks)
  • packages/taro-plugin-generator/src/generators/es5/config.ts (4 hunks)
  • packages/taro-plugin-generator/src/generators/es5/index.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: ianzone
PR: NervJS/taro#17746
File: packages/taro-runtime/tsdown.config.ts:10-16
Timestamp: 2025-05-25T18:02:31.387Z
Learning: 在 taro-runtime 包的 tsdown 配置中,必须禁用 treeshake 来保留 dom-external/index.js 文件。
packages/taro-cli/templates/default/package.json.tmpl (1)
Learnt from: ianzone
PR: NervJS/taro#17746
File: packages/taro-runtime/tsdown.config.ts:10-16
Timestamp: 2025-05-25T18:02:31.387Z
Learning: 在 taro-runtime 包的 tsdown 配置中,必须禁用 treeshake 来保留 dom-external/index.js 文件。
packages/taro-plugin-generator/src/generators/es5/index.ts (1)
Learnt from: ianzone
PR: NervJS/taro#17746
File: packages/taro-runtime/tsdown.config.ts:10-16
Timestamp: 2025-05-25T18:02:31.387Z
Learning: 在 taro-runtime 包的 tsdown 配置中,必须禁用 treeshake 来保留 dom-external/index.js 文件。
🧬 Code Graph Analysis (1)
packages/taro-plugin-generator/src/generators/es5/config.ts (2)
packages/taro-plugin-generator/src/generators/tailwindcss/config.ts (1)
  • updateConfig (12-29)
packages/taro-plugin-generator/src/index.ts (1)
  • ctx (12-47)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
  • GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
🔇 Additional comments (10)
packages/taro-cli/templates/default/package.json.tmpl (1)

115-115: 正确添加了 Vite 编译器的插件依赖

这个变更确保了在使用 Vite 编译器时也能使用 @tarojs/plugin-generator 插件,与 Webpack5 编译器保持一致。配合其他文件中对 Vite 编译器的支持,这个依赖添加是必要的。

packages/taro-plugin-generator/src/generators/es5/index.ts (4)

2-2: 正确导入了编译器类型检测函数

添加 getCompilerType 导入是为了支持不同编译器的配置修改逻辑,符合预期。


9-12: 合理的编译器类型验证

在调用配置更新前验证编译器类型是否存在,避免后续处理中出现错误。错误信息清晰明确。


14-14: 正确传递编译器类型参数

ctxcompilerType 作为对象传递给 updateConfig 函数,与 config.ts 中更新后的函数签名匹配。


27-27: ✅ 确认 browserslist 简化安全
仓库中未发现对 browserslist.development 的引用;在生成配置时也会通过 process.env.BROWSERSLIST_ENV = process.env.NODE_ENV 注入环境变量。
因此,本次将 browserslist 从对象简化为单一数组后,开发和生产环境都会使用相同的目标配置。若无单独的开发环境差异需求,该改动可直接生效;如需不同的开发环境目标,请在项目根目录新增或调整相应配置。

packages/taro-plugin-generator/src/generators/es5/config.ts (5)

13-43: 良好的编译器特定错误处理

createModifiedConfigError 函数根据不同的编译器类型生成相应的错误信息,为 Vite 和 Webpack5 提供了不同的配置示例。错误信息清晰明确,有助于开发者理解所需的配置结构。


48-49: 正确更新函数签名以支持编译器类型

将函数参数改为对象形式,包含 ctxcompilerType,这与其他生成器(如 tailwindcss)的模式保持一致,提高了代码的统一性。


62-74: 合理的编译器条件逻辑

根据编译器类型分别处理 mini 和 h5 配置:

  • Webpack5:两者都调用 modifyWebpackCompileConfig
  • Vite:mini 配置跳过(附有清晰注释说明原因),h5 配置调用 modifyViteCompileConfig

逻辑清晰,注释说明了 Vite runner 不支持小程序的 legacy 字段。


87-98: 正确实现 Vite 配置修改逻辑

modifyViteCompileConfig 函数正确处理了 legacy 属性的添加和更新:

  • 如果不存在则添加 legacy: true
  • 如果存在则更新为 true
  • 适当的错误处理机制

实现逻辑严谨,符合 Vite 编译器的配置需求。


100-133: 函数重命名提高了代码可读性

将原来的 modifyCompileConfig 重命名为 modifyWebpackCompileConfig,更明确地表达了函数的用途。函数逻辑保持不变,继续正确处理 Webpack5 的编译配置。

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch fix/generator

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai bot requested a review from yoyo837 June 30, 2025 02:45
@Single-Dancer Single-Dancer requested review from tutuxxx and removed request for yoyo837 June 30, 2025 02:48
@Single-Dancer Single-Dancer added this to the 4.1.3 milestone Jun 30, 2025
Copy link

codecov bot commented Jun 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.98%. Comparing base (d1d8b7d) to head (22cdcb5).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #17929   +/-   ##
=======================================
  Coverage   54.98%   54.98%           
=======================================
  Files         417      417           
  Lines       21693    21693           
  Branches     5356     5354    -2     
=======================================
  Hits        11928    11928           
- Misses       8083     8091    +8     
+ Partials     1682     1674    -8     
Flag Coverage Δ
taro-cli 72.42% <ø> (ø)
taro-runtime 59.87% <ø> (ø)
taro-web 53.19% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

see 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Single-Dancer Single-Dancer merged commit 0172bb4 into main Jun 30, 2025
40 checks passed
@Single-Dancer Single-Dancer deleted the fix/generator branch June 30, 2025 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants