Skip to content

Commit 8947b2c

Browse files
committed
fix for desktop apps not loading index.html after packaging
1 parent 6d757c0 commit 8947b2c

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

desktop/main.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const { app, BrowserWindow, Menu } = require("electron")
33
const path = require("path")
44
const menuTemplate = require("./menu-template")
5+
const { format: formatUrl } = require("url")
56

67
function createWindow() {
78
console.log("Creating window...")
@@ -23,7 +24,13 @@ function createWindow() {
2324
if (process.env.USE_DEV_SERVER) {
2425
mainWindow.loadURL("http://localhost:6001")
2526
} else {
26-
mainWindow.loadFile(`${process.cwd()}/build/index.html`)
27+
mainWindow.loadURL(
28+
formatUrl({
29+
pathname: path.join(__dirname, "../build", "index.html"),
30+
protocol: "file",
31+
slashes: true
32+
})
33+
)
2734
}
2835

2936
// Open the DevTools.

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"build:babel": "cross-env NODE_ENV=production babel ./src --out-dir=./lib && cp ./package.json ./lib/package.json",
1212
"build:web": "react-scripts build",
1313
"build:desktop": "cross-env REACT_APP_DESKTOP=true PUBLIC_URL=./ react-scripts build && electron-builder build && cp ./desktop/entitlements.mac.plist ./build/entitlements.mac.plist",
14-
"start:desktop": "USE_DEV_SERVER=yes electron ./desktop",
14+
"start:desktop:dev": "USE_DEV_SERVER=yes electron ./desktop",
15+
"start:desktop": "electron ./desktop",
1516
"release:lib": "npm run build && cd lib && npm publish",
1617
"release:desktop": "npm run build:desktop && electron-builder --mac --windows --linux --publish always",
1718
"release": "npm run release:desktop",
@@ -86,6 +87,10 @@
8687
],
8788
"category": "Development"
8889
},
89-
"extends": null
90+
"extends": null,
91+
"files": [
92+
"**/*",
93+
"build/"
94+
]
9095
}
9196
}

0 commit comments

Comments
 (0)