英文:
Unable to load assets when packaging electron-angular application using Electron packager
问题
我正在尝试使用Electron Packager打包我的Electron Angular项目。打包工具能够成功打包应用程序,但是当使用.exe文件启动应用程序时,没有任何资源正确加载。在开发模式下,资源可以正常加载,只有在打包应用程序时出现问题。
Angular项目包括多个库和应用程序,如下所示:
根目录
--> 项目
--> 桌面
--> 移动
--> 库 1
--> 库 2
资源位于库1和库2中,但在构建过程中,所有资源都被合并到单个资源文件夹中。
在这种情况下,我正在尝试使用Electron打包桌面应用程序。
在生产环境中构建桌面应用程序时,dist/desktop文件夹的输出
所有内部资源都是正确的。
然后是使用Electron Packager的打包命令:
electron-packager ./dist/desktop MyAppName --overwrite --asar --platform=win32 --arch=x64 --icon=projects/desktop/src/assets/logo-accent.ico --prune=true --out=dist --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=\"MyAppName\""
在打包应用程序的资源文件夹内,生成了app.asar文件。
运行应用程序时的资源文件输出错误:
我创建了一个虚拟应用程序并注意到资源可以正确加载,文件路径应该采用以下格式:
因此,在我的原始项目中缺少了红色部分。我该如何解决这个问题?
英文:
I am trying to package my electron angular project using Electron packager. The packager packages the application without errors, but when laucnhing the application with the .exe file none of the assets loads correctly. In developement mode the assets works correctly, only when packaging the application it does not work correctly.
The Angular project consists of multiple libraries and applications as follows:
Root
--> Projects
--> Desktop
--> Mobile
--> Library 1
--> Library 2
The assets are in both libraries 1 and 2, but upon building all the assets gets consolidated into a single assets folder.
I am trying to package the Desktop application with electron in this case.
The output of the dist/desktop folder when buidling the desktop application in production
All the assets inside are correct.
Then the packaging command from electron packager:
electron-packager ./dist/desktop MyAppName --overwrite --asar --platform=win32 --arch=x64 --icon=projects/desktop/src/assets/logo-accent.ico --prune=true --out=dist --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=\"MyAppName\""
The app.asar file is generated correctly inside the resources folder within the packaged application.
Output error of an assets file when running the application:
I created a dummby app and noticed that the assets work correctly and the path of the file should be in thefollowing format:
Hence the red part is missing in my original project. How would I fix this issue?
答案1
得分: 0
我的Library 1中的assets文件夹位于根文件夹中。我将assets文件夹移动到Library 1中的src文件夹中,并将所有引用更新为'assets/...',而不是'../assets...',然后它就正常工作了。
英文:
The assets folder from my Library 1 was in the root folder. I moved the assets folder into src folder in Library 1 and updated all the references to 'assets/...' instead of '../assets...' and it worked correctly.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论