DEV Community

Discussion on: React/Webpack: From MB to KB. How we solved our bundling problem

Collapse
 
rafde profile image
Rafael De Leon

if you are using babel, there's babel-plugin-lodash that can cherry pick lodash functions.
It will transform

import _ from 'lodash';
_.map([], ()=>{});
Enter fullscreen mode Exit fullscreen mode

to

import _map from 'lodash/map';
_map([], ()=>{});
Enter fullscreen mode Exit fullscreen mode

Add to your babel.config.js

// return {
    env: {
        production: {
            plugins: [
                'lodash',
            ],
        },
    },
// }
Enter fullscreen mode Exit fullscreen mode

for production builds

Also, replacing momentjs with dayjs could be a one-to-one api replacement where dayjs is less than 3kb

Collapse
 
gkampitakis profile image
Georgios Kampitakis

For dayjs that's correct. As for babel that was something I didn't know. Thanks for sharing