Vitaminaq / interview-collection

前端面试合集
3 stars 0 forks source link

tree shaking #20

Open Vitaminaq opened 2 years ago

Vitaminaq commented 2 years ago

基于es6模块实现:

  1. 只能作为模块顶层语句出现。
  2. import的模块名只能是字符串常量。
  3. import building是immutable的(编译时,确定的,静态的)。

webpack开启tree shaking的条件:官方文档

  1. 使用es6语法(即import和export)。
  2. 确保es6没有被babel等编译器转换成es5 CommonJs模式。
  3. 将"sideEffects"属性添加到项目package.json文件中。
  4. 使用 Webpack 的 production mode。