Add babel-plugin-lodash if app depends on Lodash
See original GitHub issueUpdate: 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:
- Created 7 years ago
- Reactions:11
- Comments:39 (17 by maintainers)
Top GitHub Comments
If we upgrade the lodash to v5, can we use babel-plugin-lodash in the next release of create-react-app?
Yep!
In v5 by way of removing the monolithic entry point in favor of
babel-plugin-lodash
cherry-picking.