pkg-cloudinary-core icon indicating copy to clipboard operation
pkg-cloudinary-core copied to clipboard

remove lodash dependency

Open infinityfarm opened this issue 9 years ago • 13 comments

Is there a reason for this heavy dependency, and why doesn't it manage it's own dependencies in its package.json?

infinityfarm avatar Mar 16 '16 15:03 infinityfarm

@tocker @taragano The manner in which lodash is being required by this package pulls in the entirety of lodash at least in the case of using webpack as a build tool. This makes lodash the #1 largest dependency in my app the moment I import 'cloudinary-core'. Is there a way we can open a ticket towards remedying this?

infinityfarm avatar Mar 27 '16 01:03 infinityfarm

bumping the above question - experiencing same issues.

brettcohen avatar Apr 05 '16 15:04 brettcohen

Hi @infinityfarm and @brettcohen, If you don't need the full lodash library, import the shrinkwrap library (version >= 2.0.8) or even the minified. The shinkwrap library includes only the subset of lodash functions actually used by the cloudinary library.

var cloudinary = require('cloudinary-core/cloudinary-core-shrinkwrap');
// or
var cloudinary = require('cloudinary-core/cloudinary-core-shrinkwrap-min.js');

The result:

655K  bundle.js - require('cloudinary-core')
265K  bundle.js - require('cloudinary-core/cloudinary-core-shrinkwrap')
123K  bundle.js - require('cloudinary-core/cloudinary-core-shrinkwrap-min.js')

tocker avatar Apr 06 '16 17:04 tocker

@tocker thanks, trying that out..

infinityfarm avatar Apr 06 '16 21:04 infinityfarm

I also stumbled upon this issue after seeing my bundle size for a lightweight site go from about 500kb to 2,3mb. Implementing the shrinkwrapped version did not really work for my project, and leads to _ is not defined errors.

I feel that if you make a utility library like this, you could be a bit more responsible in considering what might be uselessly sent over to some end user's computer.

Is it no option for you to only include the functions from lodash that you actually need in your package, for example with the official modularised modules?

I'd do it myself and make a pull request, but the repo seems to contain no source files, only the compiled end files.

marcohamersma avatar May 05 '17 11:05 marcohamersma

@marcohamersma the shrinkwrapped version is built similarly to the modularized lodash packages but it is more concise. Can you please share the full error of _ is not defined?

tocker avatar Jun 05 '17 09:06 tocker

Hello @tocker, I've kinda moved along from this problem by using another library, so I can't easily reproduce a stack trace for you at the moment. I should probably have included this in the first place, sorry about that 🙁.

marcohamersma avatar Jun 05 '17 13:06 marcohamersma

I'm also really want to avoid of adding big dependency to my app, especially that the image upload is mainly used from mobile devices.

@marcohamersma which library do you use?

@tocker Is their an option to use plain http/xhr requests to upload files?

idanwe avatar Apr 29 '18 09:04 idanwe

@idanwe Its possible use plain HTTP request to upload images as described here.

You could also try the shrinkwrapped version for a smaller bundle.

Makes sense?

idobarnoam avatar Apr 29 '18 11:04 idobarnoam

Yes, I find the use of the plain http API better for me, the shrinkwrapped version is better but steal for me it doesn't benefit enough to use it (I can replace it with few lines of upload code and few transformations that I used regularly in my app). (and other issue that I had that it is override the global _ variable)

Thanks for taking the time to clarify.

idanwe avatar Apr 29 '18 12:04 idanwe

Glad I could help.

If you have any further questions, please feel free to contact us at [email protected]

idobarnoam avatar Apr 29 '18 13:04 idobarnoam

@idanwe I use a slightly modified version of https://www.npmjs.com/package/withlocals-cloudinary (I forgot not why I don't use the module directly)

marcohamersma avatar May 02 '18 08:05 marcohamersma

This requires lodash to be modularized so if I want to use this I have to have both a stand build and modularized version of lodash in my project.

jwerre avatar Jul 03 '18 21:07 jwerre