A minimal electron setup in order to generate an application practically
self-contained inside a snapshot. It is based on this blog post, but this example is simpler and updated to work on Electron 12, and uses mksnapshot.js
instead of mksnapshot
- Electron 12
- OSX tested, WIN / LINUX may need to adjust the paths
npm install
Only snapshot-osx-intel is guaranteed to work. Rest of archs may have glitches in the paths, could not test them. Feel free to correct the script and create a PR.
Also, remember snapshot_blob.bin
is also arch dependent although it is generated always
with the same name AND has to have this name. So you will need appropriate magic on your publish scripts to install
the specific arch binaries.
npm run snapshot-osx-intel
npm run snapshot-osx-arm64
npm run snapshot-win
npm run snapshot-linux
npm start
This will print verbose errors in the JS file, after executing your code in a blank VM. It is useful to debug a snapshot that fails to boot.
./tool/test-snapshot.sh snapshot.src/index.js
-
- index.js
- the snapshot file that will be compiled. This is executed on a totally blank V8 context, no windows, no nodejs, no dom .... You need to use closures and instance later from the real things.
- index.js
-
- binary files will be generated here AND copied to node-modules/electron/dist.... You can delete this folder.
-
- A stub main and preloader that load all code from the snapshots
-
- An HTML application that loads all code from the snapshot
(C) 2021 Rodolfo Lopez / Nebular Streams Freeware
Thanks a lot to @jkleinsc for his comprehensive help to get this working.