webpack之Tree shaking

Tree shaking:移除多余代码。或者说按需引用。

//math.js
// 这个函数没有被其他地方引用过
export function square(x) {
     
    return x * x;
}

// 这个函数被引用了
export function cube(x) {
     
    return x 
}
//main.js
import {cube} from './maths.js';
console.log(cube(5)); // 125

以上就是用法啦。
打包后就只有cube函数,没有square函数。

你可能感兴趣的:(Webpack3.5.5)