Been working on a Electron and React app for the past 4 months and we are getting close to releasing it. This is my first production Electron app and I noticed the unpacked size was very large and the app.asar contained over 100mb of node_modules.
- My colleague wrote the electron-builder config (probably just boilerplate code - Python dev) and it includes the react build/ and node_modules/ in the electron build. I understand React doesn't need any Node_modules once it is built because all of the code is bundled and a majority of these node_modules are for the react app.
- I would assume it would be the same after electron is built/compiled. Or is it needed for nodejs deps? For the testing I did today I moved all of the react app's deps into devDeps so electron-builder doesn't include them. It reduced the unpacked size by over 80% (over 500mb to under 150mb) because it included a bunch of ui stuff like icons that were tree shaken for the built react app. Inspecting the source tree for the built react app is under 2mb for node_modules.
TLDR: does my built electron app actually need node_modules included in the build (built for linux and armv7l)? I know the react app does not after being built. And my temp work around has been moving my react deps to devDependencies so electron-builder ignores them. -- (I know this is not best practice because deploying the react app alone with a lot of services will only read the production dependencies - but shouldn't be an issue for our app's deployment)
CodePudding user response:
No, you should not need to include your node_modules
in the electron build. Most of the required dependencies should be transpiled into the build
folder.
Docs here: https://www.electronjs.org/docs/latest/tutorial/using-native-node-modules
You should also be able to test this our pretty easily. Remove node_modules
from the build target and test after running build.