Add babel-plugin-lodash if app depends on Lodash
Created by: gaearon
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.