-
Notifications
You must be signed in to change notification settings - Fork 38
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
Don't include all of lodash #131
Comments
I wrote this the other day in the vets.gov slack, so hopefully it's useful context: The history of our Lodash approach is:
The vets.gov project (and I would guess the sample app) uses a Babel plugin to automatically convert lodash imports to specific functions like you mention, so you won't save much by converting them manually. But what we've noticed is that importing specific lodash functions is much more efficient than importing specific lodash/fp functions. The way to save the most space around Lodash is I think to move to custom functions like in utilities/data for the commonly used lodash/fp functions that change data, and try to avoid lodash/fp elsewhere. |
Thanks @jbalboni! At the moment our starter app doesn't use any codemods to reduce the bundle so that might explain some of the difference in size. I've used lodash for a while and without intellisense in the editor or just reading the code it's super confusing because the lodash-fp arg order is different from lodash which I've used a lot more often. 😵 At this point I've switched to plain old replacement and destructuring in most work which AFAIK is pretty efficient and besides we've already "paid for it" by using Babel. Something like Immer looks interesting because it lets you pretend that the state object is mutable but generates a minimally changed new state from an old state. |
Yeah, I'm not nearly as much of a fan of Immer looks interesting, too, I'll have to look at that more closely. |
@dmethvin-gov Is this still an issue? I thought I saw something recently that un-lodashed us, but I might have made that up! |
@dmethvin-gov You are correct :) |
I looked into this and we are already using |
I will try experimenting with |
The plugin is working, you can see it in the built output: https://github.com/usds/us-forms-system/blob/master/lib/js/state/reducers.js#L7 (the source for that file imports We also experimented with |
It looks like @jbalboni is right, this isn't all of lodash but just what we are using, which is kind of sad given how much code it is. I agree as well that |
Currently, many files use the syntax
import _ from 'lodash/fp'
to pull in all of lodash, which tends to be a very big file. Instead they should pull in the specific functions they need via something likeimport get from 'lodash/fp/get'
. That allows tools like webpack to pull in only the needed code.However, there are also lodash-like functions being defined in https://github.com/usds/us-forms-system/tree/2410134ffda3767058ae7ef16e512e3fc5124632/src/js/utilities/data which may be better to use if they're already in this lib for other reasons. Part of this ticket would be to investigate why that's the case--should we be dropping lodash or maybe not using these custom functions? The vets.gov repo may have more history.
The text was updated successfully, but these errors were encountered: