在Mac中打开电子应用程序时出错:"file:///Applications/../Contents/Resources/app.asar/dist/index.html"



我已经为mac构建了电子应用程序,但当我运行它时,它给出了以下错误

"不允许加载本地资源:file:///Applications/e-admin.app/Contents/Resources/app.asar/dist/index.html".

以下是我所做的步骤。

1( 电子建造者构建它创建了以下文件是dist文件夹。a( e-admin-0.0.0.dmg、e-admin-0.00-mac.zip、index.html和一个mac文件夹b( 在mac文件夹中,我可以看到mac/e-admin.app/Contents/Resources/app.asar文件(而不是文件夹(

2( 我双击并安装了e-admin-0.00.dmg,然后移动到应用程序文件夹。3( 已打开应用程序。

我必须对app.asar文件做任何事情吗?(打开包装或一些东西?(或任何其他程序使其工作?

我的包.json

{
"name": "e-admin",
"version": "0.0.0",
"scripts": {
"postinstall": "electron-builder install-app-deps",
"ng": "ng",
"start": "npm-run-all -p electron:serve ng:serve",
"build": "npm run electron:serve-tsc && ng build",
"build:dev": "npm run build -- -c dev",
"build:prod": "npm run build -- -c production",
"ng:serve": "ng serve",
"ng:serve:web": "ng serve -c web -o",
"electron:serve-tsc": "tsc -p tsconfig-serve.json",
"electron:serve": "wait-on http-get://localhost:4200/ && npm run electron:serve-tsc && electron . --serve",
"electron:local": "npm run build:prod && electron .",
"electron:linux": "npm run build:prod && electron-builder build --linux",
"electron:windows": "npm run build:prod && electron-builder build --windows",
"electron:mac": "npm run build:prod && electron-builder build --mac",
"test": "ng test",
"e2e": "npm run build:prod && cross-env TS_NODE_PROJECT='e2e/tsconfig.e2e.json' mocha --timeout 300000 --require ts-node/register e2e/**/*.e2e.ts",
"version": "conventional-changelog -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
"lint": "ng lint"
},
"main": "main.js",
"private": true,
"dependencies": {...}

和angular.josn文件

"projects": {
"eAdmin": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
....

main.ts包含

if (serve) {
require('electron-reload')(__dirname, {
electron: require(`${__dirname}/node_modules/electron`)
});
win.loadURL('http://localhost:4200');
} else {
win.loadURL(url.format({
pathname: path.join(__dirname, 'dist/index.html'),
protocol: 'file:',
slashes: true
}));
}

经过多次尝试和错误,以下更改对我的有效

1( index.html

`<base href="/">` 

<base href="./">

2( 在main.ts中,将目录名dist更改为其他

来自:

win.loadURL(url.format({
pathname: path.join(__dirname, 'dist/index.html'),     
protocol: 'file:',
slashes: true
}));

收件人:

win.loadURL(url.format({
pathname: path.join(__dirname, 'angular_build/index.html'),     
protocol: 'file:',
slashes: true
}));

3( Angular.js

"outputPath": "dist/",

"outputPath": "angular_build/",

尽管我看到了改变步骤2&3,我很挑剔。看起来dist直接有些如何不起作用,必须更改为如上所述的

最新更新