我是 electron 的初学者,并用它创建了一个简单的应用程序。它使用 cmd 正确运行。然而,在使用 electron-builder 构建它并打开创建的应用程序之后,它只显示带有 Electron 框架的白色屏幕。
我认为这可能是 package.json 中的错误,但不确定在哪里?
我有 3 个 html 文件,我的文件夹中有一些图像我想打包。
我看过一些示例,但不知道在 package.json 的 "files":[ ]
中包含什么。
但是我已经尝试包含我想要打包的所有文件,但问题仍然存在
这是我的 package.json-
{
"name": "duplichecker",
"productName": "Multimedia Manager 1.2",
"version": "1.2.0",
"description": "delete duplicate and sort images and videos images at a go!",
"main": "electron-main.js",
"keywords": [
"duplichecker",
"duplicate",
"images",
"multimedia manager 1.2.0",
"multimedia manager 1.2",
"multimedia manager",
"sort"
],
"author": "hemant kumar",
"license": "ISC",
"scripts": {
"start": "electron .",
"buildi": "electron-builder",
"postinstall": "electron-builder install-app-deps"
},
"devDependencies": {
"electron": "^9.2.1",
"electron-builder": "^22.8.0",
"webpack": "^4.44.1"
},
"dependencies": {},
"build": {
"directories":{
"buildResources":"build"
},
"files":[
"build",
"node_modules",
"nulshock",
"package.json",
"index.html",
"package-lock.json",
"electron-main.js"
],
"appId": "duplichecker",
"win": {
"target": [
"nsis"
],
"icon": "build/icon.ico"
},
"nsis": {
"installerIcon": "build/icon.ico",
"uninstallerIcon": "build/icon.ico",
"uninstallDisplayName": "Multimedia Manager",
"license": "license.txt",
"oneClick": false,
"allowToChangeInstallationDirectory": true
}
}
}
也许我必须更改 main.js 中的 win.loadFile()
但要更改什么?
function createWindow () {
// Create the browser window.
const win = new BrowserWindow({
width: 600,
height: 400,
icon:'build/icon.ico',
webPreferences: {
enableRemoteModule: true,
nodeIntegration: true,
webSecurity: false
}
});
//maximizes the window;
win.maximize();
// and load the index.html of the app.
win.loadFile("index.html");
最佳答案
我解决了这个问题。当我将构建文件夹(其中只有 icon.ico)复制到“win-unpacked”——在 dist 中创建的文件夹 electron-builder 时,解压的应用程序(未打包在安装程序中)工作。 不知何故,我不知道为什么,electron-builder 没有打包 build/icon.ico 并导致我的 main.js 加载浏览器窗口图标时出错。
但是我是如何让安装程序工作的
我只是在 main.js(浏览器窗口参数)中将其路径更改为 uninstallerIcon.ico
(如果不起作用,请尝试 uninstallIcon.ico
),它将由我的 package.json 并嵌入到安装程序中,并在安装后包含在与应用程序相同的文件夹中。它使应用程序在安装设置后运行。
关于javascript - 使用 Electron Builder 构建后,Electron 应用程序未加载 index.html,甚至没有给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63878416/