我使用
electron-builder
将我的 React + Django 应用程序打包到单个可执行文件中。当我构建应用程序时,生成的 dist
文件夹包含:
-- dist (folder generated after building the app with electron)
|
|- MyApp0.0.1.exe (portable exe file)
|
|- win-unpacked
| |
| |-MyApp.exe
| |-multiple_folders (dependencies of the MyApp.exe)
| |-multiple_files (dependencies of the MyApp.exe)
问题如下:
win-unpacked
文件夹内运行 MyApp.exe时,只要依赖文件/文件夹位于同一级别,该应用程序就可以完美运行,启动和显示所需时间不到一秒。它甚至要求输入管理员密码,如在
package.json
配置中指定使用 "requestedExecutionLevel": "highestAvailable"
构建它。我尝试根据我需要的node_modules尽可能地精简项目,删除不需要的大数据文件,...
我不知道为什么会发生这种情况。我无论如何都不是网络开发专家,但我发现启动时间之间如此明显的差异过大/令人担忧。
我在这里缺少什么?这是我的
electron-builder
的 package.json
配置供参考。
"electron-build-win": "npm run build && electron-builder --win portable"
.
.
.
"build": {
"appId": "com.electron.MyApp",
"productName": "MyApp",
"asar": true,
"win": {
"icon": "./public/assets/icons/logo.png",
"requestedExecutionLevel": "highestAvailable"
},
"files": [
"build/**/*",
"./public/electron.js",
"package.json"
],
"directories": {
"buildResources": "public"
},
"extraFiles": [
{
"from": "dist-django",
"to": "dist-django",
"filter": [
"**/*"
]
}
],
"extends": null
}
同样的事情发生在我身上,显然是因为每次您以便携式模式打开它时它都会从头开始下载依赖项。