![](/img/trans.png)
[英]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.