gpbl/isomorphic500

importing imagesLoaded and other modules that required browser environment

opportunato opened this issue · 2 comments

Hey!

I've been building on top of your app my own app for quite a while — and now I want to add imagesLoaded to it. The problem is that the code is executed two times, the first time on server — where there is no browser environment and window is obviously undefined — so imagesloaded throws an error during import like this "ReferenceError: window is not defined".

How can we an approach it in the isomorphic app? I see how css is included via webpack loader – could be there some way to do the same with browser-only JS?

@opportunato just wrap your imagesLoaded code in a :

if (process.env.BROWSER) {
    ... your code here
}

Cool, thanks!