usedExports
如果想用tree shaking功能,请设置为true(好像默认就是)。
concatenateModules
开启的话webpack会实现下述情况:
// moduleA
export default (a) => {
return a + 1;
}
// moduleB
import a from "moduleA";
const x = 1;
const xx = a(x);
// 打包后moduleA会消失,代码会融合到moduleB中:
const x = 1;
const xx = x + 1;
关闭此功能,有助于调试。
minimize
代码压缩,貌似不开启的话tree shaking不会生效。
esbuild-loader
如果你用了:
const { EsbuildPlugin } = require('esbuild-loader')
module.exports = {
...,
optimization: {
minimizer: [
new EsbuildPlugin({
...
})
]
},
}
tree shaking会失效。解决办法是用webpack自带的terser来压缩js。
esbuild-loader可以正常用,只是不要用EsbuildPlugin。