Andrew Allen
Andrew Allen

Reputation: 8002

Electron builder - how to loadURL for production windows executable build

I've happily created an angular app and got this to load into Electron via loadURL.

The problem is when I build for a production exe file electron-builder build --windows than I get

__dirname = C:\Users\andrewa\AppData\Local\Temp\1UkY0hucKiKzfrpthFH75bMaiLx\resources\app.asar

What is the correct way to load index.html? Should I be using "asar": false in electron-builder.json or is there a way to load this resource?

function createWindow() {

    win = new BrowserWindow({
      width: 800,
      height: 600,
      webPreferences: {
        nodeIntegration: true
      }
    });

    win.loadURL(
      url.format({
        pathname: path.join(__dirname, `dist/index.html`), <----------- key line
        protocol: "file:",
        slashes: true
      }),
    );
}

electron-builder.json

  ...
  "win": {
    "icon": "dist/app/assets/icons",
    "target": ["portable"]
  },

Upvotes: 0

Views: 1166

Answers (1)

Andrew Allen
Andrew Allen

Reputation: 8002

This Electron Application Packaging gives details on the asar file type.

To see what's inside the app.asar file you can run the following
npx asar list /path/to/app.asar

Specific to my case I am working outside electron for a http server so I needed to include the following inside electron-builder.json which results in these being inside the folder resources/app.asar.unpacked/ the same folder as the app.asar file.

  "asarUnpack": [
    "**/dist/procurement-app/*",
    "http/*.js",
    "node_modules/mime/*",
    "node_modules/mime-types/*",
    "node_modules/mime-db/*"
  ],

Upvotes: 2

Related Questions