javascript - 构建应用程序后未加载电子 index.html
问题描述
我有一个电子应用程序,在与electron-builder
. 捆绑它并打开应用程序后,我收到以下错误:
Not allowed to load local resource: file:///tmp/.mount_displa4VwuQh/resources/app.asar/file:/tmp/.mount_displa4VwuQh/resources/app.asar/build/index.html
在构建文件夹中,我有electron.js
文件,index.html
并且由于应用程序正在启动electron.js
并因此index.html
被正确捆绑。
这是我的electron.js
应用程序入口点(基本上是样板文件):
const { app, BrowserWindow } = require('electron')
const url = require('url')
const path = require('path')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win
function createWindow() {
// Create the browser window.
win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
// and load the index.html of the app.
win.loadURL(url.format({
pathname: path.join(__dirname, './index.html'),
protocol: 'file:',
slashes: true
}));
// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null
})
}
// 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.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// 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', () => {
// 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 (win === null) {
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.
当尝试使用loadFile()
而不是loadUrl()
我得到相同的错误,但使用此路径时:file:///tmp/.mount_displa4VwuQh/resources/app.asar/index.html
知道有什么问题吗?提前致谢!
解决方案
所以看起来我的问题毕竟是由于包装不当造成的。在package.json
“构建”配置中添加它修复了它:
"directories": {
"buildResources": "build",
"app": "build"
}
推荐阅读
- python - 根据实例变量对对象数组进行排序
- azure-media-services - Azure 媒体服务:媒体/视频无法在 Safari/Edge 浏览器上解密,但在 Chrome 中运行良好
- azure-active-directory - 需要用户登录才能使用 Bot Framework 和 AAD OAuth2
- mongodb - 如何不匹配 MongoDB 内元素子数组中的文档
- r - 尝试合并两个不同长度的数据集(在 R 中使用 Combine()
- typescript - TypeScript 对象属性需要重复定义
- scala - 将包含字符串的列转换为包含 Apache Spark UDF 中的对象列表的列
- javascript - 如何对二维数组进行分组并将其转换为具有键名的对象
- json - 如何在android studio中解析多个json数组
- sql - 使用 SQL 计算留存率/流失率