chrisbateman / impetus

Agnostic utility for adding momentum to anything. It's like iScroll, except not for scrolling. Supports mouse and touch events.
chrisbateman.github.io/impetus
MIT License
487 stars 70 forks source link

fix: allow to be imported in a SSR environment #57

Open ayamflow opened 2 years ago

ayamflow commented 2 years ago

Hi ! I'm not sure if this is maintained anymore but I thought I'd share this little fix I had to do recently. I am building an app using sveltekit (svelte equivalent of next/nuxt) and Impetus, and during build, the prerender/SSR step breaks on the Impetus import because of a couple window calls (which is undefined in nodejs). It builds properly with this commit.

Maybe the requestAnimFrame fix could be done better but I have not perceived a performance impact.

Cheers !