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

17. tree shaking #18

Open
linrunzheng opened this issue Sep 16, 2021 · 0 comments
Open

17. tree shaking #18

linrunzheng opened this issue Sep 16, 2021 · 0 comments

Comments

@linrunzheng
Copy link
Owner

linrunzheng commented Sep 16, 2021

esmodule特点:

  1. 只能作为模块的顶层出现;
  2. 导入的模块名字只能是字符串;
  3. 不可改变导入后的模块;

tree shaking主要是利用了es module静态化的特点,在编译的阶段就能确定模块的依赖关系。通过静态分析找到没有引入的模块并给这些模块打上标记,最后在优化压缩阶段将这些用不到的代码删除。

由于common js支持动态导入,需要项目运行时才知道最终的模块依赖,因此common js不支持tree shaking;

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

No branches or pull requests

1 participant