[英]How to modify the folder structure of app.asar when using electron-builder?
[英]Electron Builder: Not allowed to load local resource: app.asar/build/index.html
我在使用 electron 生成器时遇到问题,我在控制台中得到空白页面和错误:
不允许加载本地资源:file:///C:/Users/emretekince/Desktop/DCSLogBook/client/dist/win-unpacked/resources/app.asar/build/index.html
主程序
const startUrl = process.env.ELECTRON_START_URL || url.format({
pathname: path.join(__dirname, '/build/index.html'),
protocol: 'file:',
slashes: true
});
mainWindow.loadURL(startUrl);
通过在package.json中添加“files”来解决
"files": [
"*.js",
"build",
"node_modules"
],
我遇到了类似的问题并且缺少path.join
:
错误代码:
win.loadFile('index.html')
固定代码:
win.loadFile(path.join(__dirname, 'index.html'))
我认为您的index.html文件不在您指定的位置。 __dirname, '/build/index.html'
我错过了这个愚蠢的观点,浪费了很多时间。 Angular-cli在dist中的文件夹内创建index.html的默认位置。
dist/project-name/index.html
我遇到了同样的问题,并设法使用以下方法对其进行排序:
path.resolve('index.html')
像这样:
const startUrl = path.resolve('index.html'); mainWindow.loadURL(startUrl);
我也遇到了同样的问题,我在加载文件之前放置了以下行。
window.webContents.openDevTools()
示例代码
// Issue code
window = new BrowserWindow({width:800,height:600,parent:mainWindow})
window.webContents.openDevTools()
window.loadURL(url.format({
pathname: path.join(__dirname,'/../views/file.html'),
protocol: 'file',
slashes: true
}))
// Issue Solved code
window = new BrowserWindow({width:800,height:600,parent:mainWindow})
window.loadURL(url.format({
pathname: path.join(__dirname,'/../views/file.html'),
protocol: 'file',
slashes: true
}))
window.webContents.openDevTools()
我试着整天解决这个问题,最后找到了解决方案,
"build": {
"appId": "myledgerapp",
"extends": null,
"files": [
"./build/**/*",
"./public/electron.js"
]}
我们需要在构建部分添加文件,其中electron.js是我的入口点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.