question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add babel-plugin-lodash if app depends on Lodash

See original GitHub issue

Update: issue is taken by @iam4x. Please don’t try to “finish it first”!

As seen in https://github.com/Automattic/wp-api-console/pull/45, it seems like a good idea to do.

While we generally don’t harcode support for libraries, Lodash is extremely popular to the point it can deserve special treatment, especially given that the plugin is easy to include conditionally and has significant benefits.

Our Babel preset could accept isUsingLodash as an option:

{
  "presets": ["react-app", {
    "isUsingLodash": true
  }]
}

It should be false by default.

Inside the preset, if isUsingLodash is true and the environment is production (we already have an if branch for environments there), we should require() and include babel-plugin-lodash (but not in other cases).

In Webpack config, we should conditionally pass isUsingLodash depending on whether app’s package.json’s dependencies contains Lodash of compatible versions.

Finally, after ejecting people who didn’t depend on Lodash should have "presets": ["react-app"] in .babelrc, but people who used Lodash at the time they ejected should see "presets": [["react-app", { isUsingLodash": true }]] in it.

Update: issue is taken by @iam4x. Please don’t try to “finish it first”!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:11
  • Comments:39 (17 by maintainers)

github_iconTop GitHub Comments

9reactions
CrisLicommented, Mar 17, 2017

If we upgrade the lodash to v5, can we use babel-plugin-lodash in the next release of create-react-app?

9reactions
jdaltoncommented, Dec 6, 2016

Are there plans to drop chain altogether in some future major?

Yep!

In v5 by way of removing the monolithic entry point in favor of babel-plugin-lodash cherry-picking.

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel-plugin-lodash-import - npm package - Snyk
1. babel-cli. add following code to .babelrc file { "plugins": [ ["./plugins/3babel-plugin-lodash/index"] ] } · 2. babel api. testd by babel api
Read more >
How to Import a Single Lodash Function? - Stack Overflow
import isEqual from 'lodash/isequal';. This works, too, but there are two minor drawbacks: You have to install the whole lodash package ( npm...
Read more >
How to shrink (tree-shake) lodash in bundle file for React ...
So, instead of grabbing the entire lodash package, ... I also discovered that there are many babel plugins that could do the job...
Read more >
babel-plugin-lodash - npm
Modular Lodash builds without the hassle.. Latest version: 3.3.4, last published: 5 years ago. Start using babel-plugin-lodash in your ...
Read more >
Minimizing Webpack bundle size - Anvil
By minimizing the size of the bundle, we reduce the time it takes for ... yarn add -D babel-plugin-lodash # or npm install...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found