sharkantropo
sharkantropo

Reputation: 15

Why does my electron-forge with webpack template makes distributables with empty node_module folders?

I'm recently trying out electron 12 with webpack bundler, and lately realized every time It builds a distributable with yarn make the build's node_module folder is empty.Hence, since I expose some modules through ContextBridge from preload.js, the app crashes and throws a missing error message.

Regardless, It works after I manually copy the entire node_module folder into it.

Upvotes: 0

Views: 820

Answers (1)

Tim
Tim

Reputation: 8186

The default configuration with electron-forge and Webpack bundles your main/preload/renderer code.

This has mostly a positive impact:

  • More compact distributables without all the cruft that that exists in node_modules
  • If you're using nodeIntegration: false there is no require in the renderers so bundling the code is a requirement if you want to use dependencies
  • Faster startup times because:
    • require'ing hundreds or possibly thousands of individual files can be slow
    • Your code is minimised and smaller so less code for Chrome to parse at startup

What are the negatives?

  • Not all node.js modules work with bundling
  • Native modules are often incompatible with bundling

Upvotes: 2

Related Questions