webpack-contrib / babel-minify-webpack-plugin

[DEPRECATED] Babel Minify Webpack Plugin
MIT License
491 stars 44 forks source link

Tree shaking not working? #43

Closed damianobarbati closed 7 years ago

damianobarbati commented 7 years ago

I'm seeing the full lodash library instead of just the map function in my vendor chunk in the compiled /build/visitor/vendor.min.js. Shouldn't just the map function be there with the following?

import { map } from 'lodash';
console.log(map([1,2], value => value**2));

Repro here => https://github.com/damianobarbati/repro-babili-tree-shaking To reproduce: git clone https://github.com/damianobarbati/repro-babili-tree-shaking yarn install yarn serve:dev #ctrl+c to close logging yarn build:prod #run webpack and babili

boopathi commented 7 years ago

This plugin doesn't do TreeShaking.

Aside: You're importing the CommonJS version of lodash where CommonJS is NOT TreeShakable.

You can either use the ESModule version of that - lodash-es

import {map} from "lodash-es";

or you can use babel-plugin-lodash.