我今天开始使用Electron,在使用电子生成器时通常会让我感到困惑。每次我跑步;npm run dist";,它创建了一个安装程序,然后继续安装,给我一个只是空白白色屏幕的可执行文件。是因为我的index.html在一个"站点";文件夹而不是主文件夹?依赖关系的图像(dist是构建时创建的文件夹(
package.json
{
"name": "governmentmayhem",
"version": "2.0.0",
"description": "Government Mayhem v2 by harrup and Troxx",
"main": "main.js",
"scripts": {
"start": "electron .",
"dist": "electron-builder",
"electron-pack": "electron-builder --win -p always"
},
"build": {
"appId": "com.electron.app",
"win": {
"target": "nsis",
"icon": "site/assets/logo.ico"
},
"extraFiles": [
"site"
]
},
"author": "harrup and Troxx",
"license": "ISC",
"devDependencies": {
"electron": "^20.0.3",
"electron-builder": "^23.3.3"
},
"dependencies": {
"asar": "^3.2.0",
"path": "^0.12.7"
}
}
main.js
const { app, BrowserWindow } = require('electron');
const path = require('path');
const createWindow = () => {
const win = new BrowserWindow({
width: 1280,
height: 720,
minWidth: 1280,
minHeight: 720,
});
win.setAspectRatio(16/9)
win.setMenu(null);
win.setIcon('site/assets/logo.ico')
const dir = path.join(__dirname, 'site/index.html');
win.loadURL(`file://${dir}`);
}
app.on('window-all-closed', () => {
if (process.platform !== 'darwin'){
app.quit();
}
})
app.on('ready', createWindow)
我只是简单地重做了整个项目,就成功地修复了它。不知道它是如何修复的,但之前的项目有许多随机安装的依赖项(电子封装程序、url和路径(。我想,试着让你的项目干净一点吧。