Skip to content

Remove lodash from dependancy to reduce bundle size

Ankit Panchal requested to merge ankit.panchal/reduce-bundle-size into main

Currently, bundle size for gl-sdk.min.js is ~111kb without any plugins.

while snowplow browser tracking bundle size is ~40kb.

Turns out it is due to isEmpty function that we are using from lodash.

import { isEmpty } from 'lodash'

ideally, we should be using like below so that rollup treeshaking can pick only isEmpty

import isEmpty  from 'lodash/isEmpty'

After this change bundle size becomes ~44kb which is close to snowplow bundle size.

As we are using only isEmpty function from lodash, I have created same function instead of using it from lodash. We can look at importing lodash in future, if we have more use for it.

With our own function size reduces to ~40kb. which is same as snowplow library.

Merge request reports