webpack自带的优化
index.js文件
// import jquery from 'jquery'
import calc from './test.js';
// import 在生产环境下,会自动去除没用的代码
// tree-shaking 把没用到的代码 自动删除掉
// 如果使用require 则不会进行优化
// es6模块会把结果放到default上 使用calc.default.sum
console.log(calc.sum(1,2));
// scope hosting 作用域提升,
let a =1;
let b = 2;
let c = 3;
let d = a+b+c; // webpack中自动省略可以优化的代码
console.log(a);
console.log(d, '-----------'); // =>会被优化为console.log(6);
function f() {
console.log(b);
}
f();