【发布时间】:2020-10-05 21:26:58
【问题描述】:
我正在尝试构建一个 Electron 应用程序。为此,我正在使用以下响应:
https://github.com/electron/electron-quick-start
https://github.com/electron-userland/electron-builder
在 devoplement 模式下(电子。)一切正常。但是当我构建应用程序并启动它时,它只是在开发控制台或构建日志中显示一个空白页面,没有任何错误。
为什么它在生产中不起作用?我所有的文件都在一个方向:
- index.html
- main.js
- renderer.js
- package.json
我在基本 main.js 文件中没有太大变化:
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
const path = require('path')
const url = require('url')
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
frame: false,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true,
webSecurity: false
}
})
// and load the index.html of the app.
//mainWindow.loadFile('index.html')
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}));
// Open the DevTools.
mainWindow.webContents.openDevTools();
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') app.quit()
})
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
【问题讨论】:
标签: javascript electron electron-builder