I am trying to use ZeroMQ (0MQ) inside an Electron application: npm add zeromq@6.0.0-beta.19
and electron@22.3.24
and @electron-forge/cli@6.0.5
On my local machine, for development, everything works as long as I declare the module as external in my webpack configuration. Alternatively, I also need to exclude zeromq from the rebuild process on my Mac M1 (that's another story):
// webpack.main.config.jsmodule.exports = { // ... externals: {'zeromq': 'commonjs zeromq' }, // ...}
// forge.config.jsmodule.exports = { // ... rebuildConfig: { onlyModules: "axios", // prevent rebuilding on Mac as headers are missing }, // ...}
But in order to package my application and distribute it, I found no other alternative than a hook to copy zeromq module into the destination folder. This seems brittle, and inefficient at best. Is there another solution to have Electron Forge handle external modules gracefully?
// forge.config.jsconst fs = require('fs');const path = require('path');module.exports = { packagerConfig: { extraResource: ["./node_modules/zeromq/","./node_modules/@aminya/", ], afterCopyExtraResources: [ (bPath, eVer, platform, arch, done) => { let src ; let dst ; for (const m of ["zeromq", "@aminya"]) { if (platform === "darwin") { src = path.join(bPath, "jelo-ui.app", "Contents", "Resources", m) dst = path.join(bPath, "jelo-ui.app", "Contents", "Resources", "app", "node_modules", m) } else { src = path.join(bPath, "resources", m) dst = path.join(bPath, "resources", "app", "node_modules", m) } fs.renameSync(src, dst) } done(); } ] },// ...}