feat(pack): support optimization.removeUnusedExports & codegen modules without module graph#2239
feat(pack): support optimization.removeUnusedExports & codegen modules without module graph#2239fireairforce merged 2 commits intonextfrom
Conversation
…s without module graph
Summary of ChangesHello @fireairforce, 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! 此拉取请求引入了一个新的优化功能,允许用户配置是否移除未使用的导出,从而减小最终打包体积。此功能通过在生产环境中默认启用,而在开发环境中默认禁用,以平衡开发效率和生产性能。同时,它还包含了对 Turbopack 核心导出使用分析机制的底层更新,确保了优化逻辑的正确性和效率。 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
这个 PR 引入了一个很有价值的优化(removeUnusedExports),用于移除未使用的导出,这有助于减小生产环境下的包体积。实现看起来很可靠,并且默认行为(生产环境开启,开发环境关闭)是合理的。将函数参数重构为专门的 Options 结构体(如 ClientChunkingContextOptions 和 LibraryChunkingContextOptions)的做法,对于代码清晰度和可维护性来说是一个巨大的改进,尤其是在 turbo_tasks 框架中。
我提出了一些关于次要重构的建议,以提高代码的清晰度并遵循 Rust 的惯用写法。总的来说,这是一个很棒的贡献。
Summary
新增一个配置
optimization.removeUnusedExports用于移除未使用到的导出。该配置在 production 场景下默认开启,dev 场景下默认为 false。同时 apply turbopack 底层的 export_usage 变更: vercel/next.js#81238
用于节省在 modules 生成时候的内存占用。
Test Plan
参考快照测试的变更