I'm trying to use webpack to bundle react code that gets rendered server-side and client-side. Some libs I'm trying to use (like glidejs) completely assume they are executing in the browser.
I'm not actually using the lib until componentDidMount or at some other point which won't execute on the server.
How can I require them but basically just have them do nothing in the node environment?
Glidejs specifically wants jquery, window, and document. Giving it jquery seems fine but I don't know what to do about window and document.
I haven't found a beautiful solution for this problem too, but – at least – there are two possible solutions:
You could bundle your node.js code with webpack by specifying node
as target
. Then you can alias client-side code with empty stubs.
You can require()
empty stubs and alias them in your webpack config to the real modules.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With