Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lodash #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Remove lodash #9

wants to merge 4 commits into from

Conversation

cesine
Copy link

@cesine cesine commented Sep 25, 2020

Smaller bundle size

We noticed our bundle is importing lodash (23.99 gzipped) because it facebook-locales is importing the entirety of lodash as _. This is an older pattern which impacts bundle size for consumers of this repo.

Screen Shot 2020-09-25 at 1 49 12 PM

What we would prefer instead, would be for facebook-locales' usage of lodash to fall into the other lodash usages in our bundle which is tree shaken down to (4.29 gzipped)

Screen Shot 2020-09-25 at 1 49 54 PM

Options

A straightforward solution is change the imports to:

import map from 'lodash/map';
...

When I looked into the code, I saw that the majority of the usages are simple functions which are now available on array. Given that array functions are now supported in most browsers (and are polly filled for those who are building for non-modern browsers) now is a good time to migrate from lodash to native functions.

  • So rather than replacing them with a treeshakable import, I replaced the lodash usage with the array function equivalents.

How this was tested

$ npm test

> facebook-locales@1.0.2 test  facebook-locales
> mocha --compilers js:babel-register



  FacebookLocales
    ✓ supports the default locale: English (United States)
    ✓ supports a standard locale: French (France)
    ✓ supports a non-standard locale: Spanish (Latin America)
    ✓ supports a non-standard locale: Arabic
    ✓ makes best effort to return a supported Facebook locale with the same langauge as an unsupported locale
    ✓ falls back to English (United States) if all else fails


  6 passing (166ms)
$ npm run compile

> facebook-locales@1.0.2 compile facebook-locales
> babel -d dist/ src/

src/Facebook.js -> dist/Facebook.js
src/FacebookLocales.js -> dist/FacebookLocales.js
src/index.js -> dist/index.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants