lodash / babel-plugin-lodash

Modular Lodash builds without the hassle.
Other
1.96k stars 92 forks source link

Document how import transformation works #172

Closed danny-andrews closed 7 years ago

danny-andrews commented 7 years ago

First off, thanks for the great plugin! It's made it really easy for us to reduce our bundle size without changing imports all over the place. However, I think the documentation should be expanded to give instructions on how to use it with libraries other than lodash. I realize there is a name-change in the works, but it would be nice to have some basic docs in the meantime.

Specifically, it would be nice to have an explanation of how the import transformation works, i.e., how, with the following .babelrc config:

{
  "plugins": [["lodash", { "id": ["material-ui", "redux-form-material-ui"] }]]
}

imports from both material-ui and redux-form-material-ui are both transformed correctly, despite material-ui storing all modules at the top-level directory and redux-form-material-ui storing stuff in lib. How does this plugin figure that out!?

I'd be happy to make a PR for this, but I can't since I myself don't know how it works. :D

jdalton commented 7 years ago

Hi @danny-andrews!

The plugin crawls the package looking for matching modules. It looks first in the folders of the "main" entry script and then in others. This is how it finds the redux-form-material-ui/lib folder. Feel free to make a PR to add a note to the readme.