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

deps(lodash): migrate lodash to lodash-es #16211

Merged
merged 2 commits into from
Oct 11, 2024

Conversation

ChristopherPHolder
Copy link
Contributor

@ChristopherPHolder ChristopherPHolder commented Oct 6, 2024

Summary

Improve Tree-Shaking and bundling by migrating from lodash to lodash-es.

Even tho we are now using individual imports as of #13914 we are still using ComonJS. But since the rest of the repo seems to have migrated to ESM we can now use the ESM packages for lodash which is lodash-es.

An addition benefit of this is that if the code is bundles futher by esbuild it will not require wrapping the use of lodash like this:

image

Related Issues/PRs

Copy link
Member

@adamraine adamraine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested the bundle size, we go from 1807771 bytes to 1806087 bytes (so a savings of ~1.6KB)

@@ -12,7 +12,7 @@

/* eslint-disable no-console */

import cloneDeep from 'lodash/cloneDeep.js';
import cloneDeep from 'lodash-es/cloneDeep.js';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect the advantage of tree-shaking to be that we can import everything from the top-level entry point now. For example:

Suggested change
import cloneDeep from 'lodash-es/cloneDeep.js';
import {cloneDeep} from 'lodash-es';

Is this something you could do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will make the changes 👌

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are done

@ChristopherPHolder
Copy link
Contributor Author

I just tested the bundle size, we go from 1807771 bytes to 1806087 bytes (so a savings of ~1.6KB)

How can i generate a metafile to check the bundle?

I am trying to run the build but having multiple issues. I guess the command should be yarn build-all?

This is the error i get:

$ node ./build/build-cdt-lib.js
$ yarn build-extension-chrome && yarn build-extension-firefox
$ node ./build/build-extension.js chrome
$ node ./build/build-extension.js firefox
$ yarn reset-link && node ./build/build-bundle.js clients/devtools/devtools-entry.js dist/lighthouse-dt-bundle.js && node ./build/build-dt-report-resources.js
$ (yarn unlink || true) && yarn link && yarn link lighthouse
success Unregistered "lighthouse".
info You can now run `yarn unlink "lighthouse"` in the projects where you no longer want to use this package.
success Registered "lighthouse".
info You can now run `yarn link "lighthouse"` in the projects where you want to use this package and it will be used instead.
success Using linked package for "lighthouse".
X [ERROR] Syntax error "s"

    core/user-flow.js:43:50:
      43 │ const str_ = i18n.createIcuMessageFn({url: 'core\user-flow.js'}.url, UIStrings);
         ╵                                                   ^

X [ERROR] Could not resolve "./messages"

    node-modules-polyfills:__zlib-lib/binding:1:16:
      1 │ import msg from './messages';
        ╵                 ~~~~~~~~~~~~
        

@adamraine
Copy link
Member

I just checked the bundle size myself (1806556 bytes, so still good)

Not sure what the issue is exactly, are you running on windows? Might be an issue with / vs \ in windows paths.

@adamraine adamraine changed the title deps(lodash): migrate lodash to lodash-es to improve tree-shaking deps(lodash): migrate lodash to lodash-es Oct 10, 2024
@adamraine adamraine merged commit a9c313e into GoogleChrome:main Oct 11, 2024
24 checks passed
@connorjclark
Copy link
Collaborator

yarn build-all, du -sh dist/**/*

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

Successfully merging this pull request may close these issues.

4 participants