Foliotek / Croppie

A Javascript Image Cropper
http://foliotek.github.io/Croppie
MIT License
2.58k stars 884 forks source link

Issue #656, Allow to be included into NodeJS without breaking #657

Closed ofzza closed 5 years ago

ofzza commented 5 years ago

Adds environment checks before using environment specific features during initialization. This allows the library to be required/imported even outside of a browser environment without crashing the environment.

Handles issue #656.

thedustinsmith commented 5 years ago

This PR seems fine to me. Out of curiosity - why are you importing croppie in a nodejs environment?

ofzza commented 5 years ago

@thedustinsmith I bundle it as part of client-side React code in my application, and then use this same bundle for both server-side rendering and client-side rendering of the app. For the server-side rendering part, the bundle needs to be included from inside a NodeJS server-side part, which causes the bundled Croppie library to initialize and throw errors.

I could, of course, make 2 bundles - one for client-side and another for server-side with stubbed libraries that cause issues - but this would prolong my build times and so far it wasn't needed; and in this case the fix seems to be easy and should have no adverse impact on Croppie.

thedustinsmith commented 5 years ago

Agreed. Just curious. Thanks!

I'll merge this in, but I can't promise any sort of release any time soon.

tanmoyopenroot commented 4 years ago

@thedustinsmith , Is the fix deployed? Still getting window is not defined