-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Packages: Replace usage of lodash with lodash-es #9374
Conversation
Should we update the webpack config to define |
I'm wondering about the |
I think we have it covered:
Yeah, good question :) |
@@ -96,6 +96,7 @@ | |||
"jest-puppeteer": "3.2.1", | |||
"lerna": "3.0.0-rc.0", | |||
"lint-staged": "7.2.0", | |||
"lodash": "4.17.10", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node 8 doesn't have ES modules enabled natively so we need to use lodash
in all CLI tools.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there's some breaking in e2e tests, I guess it's related?
e2e tests fail because of the missing Now that I think about it, we probably should have |
I don't think |
|
I'd wondered if we could just use an alias such that a developer could import as though from |
Yes, I’m coming to the same conclusion after seeing what kind of issues the current proposal creates. |
As discussed during the weekly JS chat yesterday, it won't work as intended in the current form. Ideally we should wait for |
I experimented with The main awkwardness is in how a package would need to define its dependency as diff --git a/packages/babel-preset-default/index.js b/packages/babel-preset-default/index.js
index d62a0c02d..63793941d 100644
--- a/packages/babel-preset-default/index.js
+++ b/packages/babel-preset-default/index.js
@@ -21,6 +21,11 @@ module.exports = function( api ) {
} ],
'@babel/plugin-proposal-async-generator-functions',
! isTestEnv && [ '@babel/plugin-transform-runtime', { corejs: 2 } ],
+ [ 'module-resolver', {
+ alias: {
+ lodash: 'lodash-es',
+ },
+ } ],
].filter( Boolean ),
};
}; |
Should we close this pull request? |
Yes, it will have to list both lodash versions as dependencies and lodash-es will only be used after being published to npm 😃 |
Did something to do with lodash or underscores make it to 3.7? My custom JS file had some I fixed it with some webpack config (to use |
If you use Before So each time you use an external script, don't forget to add it as a dependency to your script to avoid breakage when we update Gutenberg's code. |
Gotcha. These are still reliable to use though? https://github.com/WordPress/gutenberg/blob/master/webpack.config.js#L116-L124 |
yes, don't forget the dependencies in your wp script definition, that's it. |
Is there any chance to revisit the closing of this PR? |
As far as I remember, the issue with
By the way, npm in the latest 6.9.0 release introduced aliases (https://npm.community/t/release-npm-6-9-0/5911):
Examples from the test suite in the commit (npm/cli@b7b54f2):
|
Thanks for the response @gziolo! |
@ocean90 maybe you can install both dependencies and only alias it in the webpack config. |
Description
This PR replaces all usage of
lodash
withlodash-es
in app code. It still useslodash
for tools which can't use ES modules.This aims to improve the size of published packages by using the version of lodash which can be optimized with tools like Webpack using tree shaking.
How has this been tested?
npm test
npm run dev
Types of changes
Refactoring.
Checklist: