You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to modify some files before packing using the distributed node/electron, the problem is that I'm building it on a x64 machine and the distributable is x86 (meaning I can't just use node_modules/electron).
beforePack hook doesn't work because distributable electron hasn't been downloaded/unziped yet, and afterPack already has the asar archive.
I did find a solution using the @electron/asar package:
set asar: true and asarUnpack: '**/*' this is for electron-builder don't throw error saying the main.js doesn't exist.
then the afterPack hook:
importasarfrom'@electron/asar';import{FuseV1Options,FuseVersion,flipFuses}from'@electron/fuses';importfsfrom'node:fs';importpathfrom'node:path';asyncfunctionafterPack(context){constfileName=context.packager.appInfo.productFilename;constbinPath=path.join(context.appOutDir,`${fileName}.exe`);// Modifying some filesawaitcompileFile({filename: path.join(context.appOutDir,'resources/app.asar.unpacked/dist/main.js'),node: binPath,});// Packing to asarawaitasar.createPackage(path.join(context.appOutDir,'resources/app.asar.unpacked'),path.join(context.appOutDir,'resources/app.asar'),);// Remove leftover filesfs.rmSync(path.join(context.appOutDir,'resources/app.asar.unpacked'),{recursive: true,force: true,});// Flip fusesawaitflipFuses(binPath,{version: FuseVersion.V1,[FuseV1Options.RunAsNode]: false,[FuseV1Options.OnlyLoadAppFromAsar]: true,});},
It appears to have worked correctly, and the build size is smaller, but I would like to know if there's a better solution or any downsides to it, does it break the NSIS auto updater?
Thanks!
The text was updated successfully, but these errors were encountered:
After playing a bit with @electron/packager, I could use their afterCopy hook to accomplish that.
Another option I can think of, would be using @electron/get to download the distributed version and modify the files before electron-builder. Doesn't feel right though since electron-builder already does it.
I didn't test but using @electron/asar probably breaks autoupdater from electron-builder.
For those who's gonna look at this in the future, what I'm gonna do is use the afterExtract hook to get the distributed node/electron and modify the files before they get packed.
Related: #5619
I need to modify some files before packing using the distributed node/electron, the problem is that I'm building it on a x64 machine and the distributable is x86 (meaning I can't just use
node_modules/electron
).beforePack
hook doesn't work because distributable electron hasn't been downloaded/unziped yet, andafterPack
already has the asar archive.I did find a solution using the
@electron/asar
package:asar: true
andasarUnpack: '**/*'
this is for electron-builder don't throw error saying the main.js doesn't exist.It appears to have worked correctly, and the build size is smaller, but I would like to know if there's a better solution or any downsides to it, does it break the NSIS auto updater?
Thanks!
The text was updated successfully, but these errors were encountered: