1

While the preload script loads ok when developing yarn start

It does not on builds yarn make

Unable to load preload script:
  const mainWindow = new BrowserWindow({
    width: 1800,
    height: 1600,
    webPreferences: {
      nodeIntegration: true,
      sandbox: false,
      preload: path.join(app.getAppPath(), 'preload.js')
    },
  })

Is there any evident reason for that?

GWorking
  • 4,011
  • 10
  • 49
  • 90

1 Answers1

2

Several questions and issues about this one, such as

The answer is this one https://stackoverflow.com/a/67176486/826815, adapted for js, also described in the docs https://www.electronforge.io/config/plugins/webpack#project-setup

const mainWindow = new BrowserWindow({
  webPreferences: {
    preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
  }
});
              "entryPoints": [
                {
                  "html": "./src/index.html",
                  "js": "./src/renderer.js",
                  "name": "main_window",
                  "preload": {
                    "js": "./src/preload.js"
                  }
                }

Being preload.js in the /scr/ folder, and checking that afterwards it is present in the /out/ folder

GWorking
  • 4,011
  • 10
  • 49
  • 90
  • setting any `entry` in webpack make preload stop to work. Any idea What could possibily be the reason? – Jack Apr 04 '22 at 06:23