Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Build: Reference Lodash as an external module #5933
This pull request seeks to reference Lodash as an external module (window global), rather than include in the build of each bundle.
Before: 1783.1 KiB
Net savings: 201 KiB (11.2%)
Babel Preset: We need to drop
Verify there is no regressions in the build (including plugin-packed), and that the application loads and operates as expected.
I'm all for merging this to avoid a Lodash incarnation of the above issue in the future and as Core doesn't currently enqueue Lodash as it is only installed as part of npm
Doing this now should be an easy win versus the latter alternative.
Managed to get tests to pass again by faking a
Rebased again to include explicit references to Babel dependencies otherwise available only via implicit transitive dependency.
I also noticed in some unrelated effort toward a Babel 7 upgrade that we'll need other changes to the Babel configuration, so it may be a good idea to group these upstream changes.
I was asked in last week's Core JS meeting to justify the inclusion of Lodash, when core already includes Underscore, a similar library. Rather than reiterate common points, I'll simply defer to a well-abbreviated comparison discussion, with a summary of superiority in: features, documentation, testedness, maintenance, performance, consistency, adherence to the language specification (naming like
I'll acknowledge that one of the original points for its inclusion was its modularity and being able to selectively import features (#289), which is very much ironic given the presence of this pull request to use the entire library instead. I'd not want to dismiss this possibility altogether, as its an area of continuous improvement (see Webpack 4's
I'll let the pull request sit until a recap discussion in tomorrow's JS meeting, but I'd like to have this merged ahead of the next release unless there's objection.
@aduth Thanks for the explanation.
When I asked you to "justify the inclusion of Lodash" I wasn't really asking about underscore vs. lodash - although I appreciate your reasoning there. I was more asking whether its merits are sufficient to warrant not using the already bundled in WordPress underscore. Isn't underscore already being loaded on the post edit page for
It sounds like you think they are... Great! If we are switching to Lodash, do you think that means we should switch that across core to avoid loading duplicate, redundant libraries?
Discussed in this week's core JS chat: https://wordpress.slack.com/archives/C5UNMSU4R/p1523367666000160
Consensus is to move forward with this merge, and work toward migrating existing core usage of Underscore.
Related Trac ticket: https://core.trac.wordpress.org/ticket/43733