Webpack: ignore server-side client libraries

I am trying to use webpack to bind a reaction code that gets the server and client sides displayed. Some libraries I'm trying to use (e.g. glidejs ) fully assume that they run in a browser.

I actually do not use lib until the ComponDidMount component or at some other point that will not be executed on the server.

How can I require them, but basically they just do nothing in the node environment?

Glidejs specifically wants jquery, window and document. The jQuery rendering seems fine, but I don't know what to do with the window and the document.

+6
source share
1 answer

I also did not find a beautiful solution to this problem, but at least there are two possible solutions:

  • You can link your node.js code to webpack by specifying node as target . Then you can pseudonize client code with empty stubs.

  • You can require() empty stubs and their alias in your webpack configuration for real modules.

+1
source

Source: https://habr.com/ru/post/984473/


All Articles