入口文件index.js
import { a } from "./test.js";
console.log(a);
test.js
export const a = 1;
export const b = 2;
console.log("11111111");
test中的b变量没引用,所以要treeshaking掉,test中的console语句也是副作用,我在package.json中设置了 "sideEffects": false, webpack的mode已经设置成production了,为啥test中console语句还是被打包进去了
打包结果
(()=>{"use strict";console.log("11111111"),console.log(1)})();
console.log()
当然应该打包进去,“输出内容” 是软件功能的一部分。不想要的话,在压缩的时候配置drop_console
就好。