27

我已经开始学习 Angular 2 并且遇到了“tree shaking”这个术语,但我无法从初学者的角度找到任何好的解释。

我在这里有两个问题:

  1. 什么是摇树,我为什么需要它?
  2. 我该如何使用它?
4

3 回答 3

40
于 2019-05-01T12:23:47.347 回答
27

这只是意味着将删除您项目中但未在任何地方使用/引用的代码。就像您导入一个完整的库只是为了在其中使用 1 个函数一样。它减少了编译代码的大小。

于 2017-08-25T15:10:23.350 回答
1

The Tree Shaking process reduces the download size of an application
Tree shaking not exporting the modules that are not needed by our application in the bundle file, it is not going to remove the unused code from the bundle.
Webpack removes the links and UglifyJs Plugin removes the code

于 2021-06-03T16:49:07.810 回答