Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

babel-plugin-lodash #1653

Closed
c0debreaker opened this issue Feb 26, 2017 · 10 comments
Closed

babel-plugin-lodash #1653

c0debreaker opened this issue Feb 26, 2017 · 10 comments

Comments

@c0debreaker
Copy link

I'm having a hard time digging through the closed issues looking for solutions on how to use this plugin. Can it be used with create-react-app without ejecting our app?

Thanks!

@Timer
Copy link
Contributor

Timer commented Feb 26, 2017

Unfortunately, no. It cannot be used without ejecting.
We will reconsider this feature if lodash drops chain from the API.

You can, however, use the method described here to reduce your bundle size.

@Timer Timer closed this as completed Feb 26, 2017
@c0debreaker
Copy link
Author

Thanks a lot!

@Timer
Copy link
Contributor

Timer commented Feb 26, 2017

No problem!

@c0debreaker
Copy link
Author

It didn't work for me. The bundle size became larger

Using the lodash that came with create-react-app

Creating an optimized production build...
Compiled successfully.

File sizes after gzip:

  237.92 KB  build/static/js/main.f953a88f.js
  1.83 KB    build/static/css/main.2bf0ac43.css

Then i ran rm -rf build and installed lodash.groupby and lodash.foreach. I used it this way

import _groupBy from 'lodash.groupby';
import _forEach from 'lodash.foreach';

and here are the results

Creating an optimized production build...
Compiled successfully.

File sizes after gzip:

  241.14 KB  build/static/js/main.96d96f68.js
  1.83 KB    build/static/css/main.2bf0ac43.css

@Timer
Copy link
Contributor

Timer commented Feb 26, 2017

You may be depending on a different version of lodash than you're installing using that unsupported behavior, but I suggest using the slash method not dot.

@c0debreaker
Copy link
Author

Ok, I'll try it.

@c0debreaker
Copy link
Author

I tried lodash/groupby and lodash/foreach and here are the results

File sizes after gzip:

  242.85 KB  build/static/js/main.0d2dc2db.js
  1.83 KB    build/static/css/main.2bf0ac43.css

@Timer
Copy link
Contributor

Timer commented Feb 27, 2017

Like I said, "Using the lodash that came with create-react-app" is not a supported behavior and properly importing lodash is probably grabbing a newer, larger version of the library.

Sorry, but I don't think you can tune this much more without ejecting. 😬 Though I don't think babel-plugin-lodash is going to fix this problem.
Let me know if you find out more information and we can add it to the readme. 😄

@gaearon
Copy link
Contributor

gaearon commented Feb 27, 2017

All babel-plugin-lodash does is replace imports like import { groupBy } from 'lodash with imports like import groupBy from 'lodash/groupBy'. It won’t magically make the bundle smaller, and if you already write granular imports, this is as good as it will get.

And yea, you need to npm install --save lodash.

@c0debreaker
Copy link
Author

c0debreaker commented Feb 27, 2017

Yup, after doing a lot of trial and error even with Dan's suggestion, the difference wasn't that much. However, guess what I found out? I changed the way I was importing Material-UI and OMG, I brought it down to 154KB. I'm very happy for that :)

Thanks to both you! Oh, I LOVE CREATE-REACT-APP so much! This is the best creation next to loaf of bread. :)

@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants