Skip to content
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

feat(tree-shaking):skip-module according to side-effects #807

Merged
merged 22 commits into from
Dec 25, 2023

Conversation

stormslowly
Copy link
Member

@stormslowly stormslowly commented Dec 20, 2023

close #727

尺寸性能

bigfish 模板项目

3032    dist-current
3284    dist-origin
2736    dist-webpack

120% = 3284/2736 --> 110.8% =3032/2736

solution Overview

step 1. 首先确定 proxy 模块没有副作用,
step 2. 分析 import specifiers from "proxy" 或者 export specifier from "proxy", 得到需要从 proxy 模块中引用的符号 ident,
step 3. 使用 ident 在 proxy 模块查找它的来源模块和对应的引用符号 ident',继续查找;查找的结束条件

  1. ident 在本文件定义
  2. ident 可以在一个有副作用的文件中定义
  3. 在 proxy 文件查找不到 ident 的定义(例如,ident 来自一个 cjs 模块,模块中使用 export * from 'cjs')
  4. ident 的定义来自 namespace 导出 (例如 export * as foo from “m”)

step 4. 替换原始模块中 ident 的导入方式
step 5 重新分析模块依赖信息,重建对应的 tree-shaking 模块中的 statement graph 和 语句 exports 信息

detail

wip 内部分享

crates/mako/Cargo.toml Show resolved Hide resolved

pub fn analyze_deps(
ast: &ModuleAst,
task: &Task,
file_path: &String,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个没特别的理由不要调整。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有,skip modules 之后,ast 会变化,ast 需要重新分析,这个时候分析deps 是没有 task 这个概念的。

crates/mako/src/config.rs Outdated Show resolved Hide resolved
@sorrycc sorrycc merged commit 1d4a43b into master Dec 25, 2023
8 checks passed
@delete-merged-branch delete-merged-branch bot deleted the feat/re_export_with_side_effects branch December 25, 2023 02:04
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.

feature request: 降低产物尺寸 10%
2 participants