Tree Shaking只支持ES6的 ES module

Tree Shaking只支持ES6的 ES module

webpack.config.js

module.exports={
	mode:'development'
	...,
	optimization:{
		usedExports:true
	}
}

package.json

{
	"name":"lesson",
	//方式一
	"sideEffects":false,
	//方式二
	"sideEffects":[
		"*.css"
	],
}
  1. 当webpack配置文件中设置为开发模式时,默认不支持Tree Shaking,需要增加optimization:{usedExports:true}属性;
  2. import导入模块没有返回值的情况下,webpack在打包编译时Tree Shaking默认会忽略掉此文件,例如css文件、babelpolyfill等模块;
  3. 开发环境下,为了便于SourceMap调试,Tree Shaking不会删除没有用到的代码块,而是标注为 exports provided:add, minus exports used:add 导出了哪些模块,用到了哪些模块

猜你喜欢

转载自blog.csdn.net/xiaofanguan/article/details/88926687