上周我一直在解決以下問題 - 我想將我的 Ionic 專案不僅編譯為 android 版本,而且還編譯為電子桌面應用程式。但是,每次我部署打包電子版時,我都會有一個白屏。
如何重現問題:
# i create simple angular app
ionic start example-app tabs --type angular
cd example-app
# i add @capacitor-community version of electron, since the original electron is deprecated
npm i @capacitor-community/electron
# required to get a www folder
ionic build
# add electron folder to project
npx cap add @capacitor-community/electron
# now we work inside electron project...
cd electron
# we can build project
npm run build
# we can start live project
npm run electron:start-live
# and now we have crash - just a blank white window
npm run electron:pack
uj5u.com熱心網友回復:
我已經能夠在部署版本中獲得可見視窗,在./electron/src/setup.ts檔案中進行以下更改。您需要找到以下片段:
// Set a CSP up for our application based on the custom scheme
export function setupContentSecurityPolicy(customScheme: string): void {
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
callback({
responseHeaders: {
...details.responseHeaders,
'Content-Security-Policy': [
electronIsDev
? `default-src ${customScheme}://* 'unsafe-inline' devtools://* 'unsafe-eval' data:`
: `default-src ${customScheme}://* 'unsafe-inline' data:`,
],
},
});
});
}
并將其更改為:
// Set a CSP up for our application based on the custom scheme
export function setupContentSecurityPolicy(customScheme: string): void {
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
callback({
responseHeaders: {
...details.responseHeaders,
'Content-Security-Policy': [
`default-src ${customScheme}://* 'unsafe-inline' devtools://* 'unsafe-eval' data:`
],
},
});
});
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/312553.html
上一篇:@capacitor-community/electron在構建的包上給出未處理的承諾拒絕
下一篇:IonicCordova構建始終使用最新版本的androidx.appcompat:appcompatn并且失敗
