使用 Electron-builder 构建的便携式 Windows 应用程序启动时间太长

问题描述 投票:0回答:1

我使用

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"
    构建它。
  • 运行 MyApp0.0.1.exe 时,它应该是应用程序的可移植、独立的 .exe 文件,尽管它确实运行得很好,但需要 最多 6 分钟才能启动 并显示应用程序.

我尝试根据我需要的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
  }
reactjs django electron startup electron-builder
1个回答
0
投票

同样的事情发生在我身上,显然是因为每次您以便携式模式打开它时它都会从头开始下载依赖项。

© www.soinside.com 2019 - 2024. All rights reserved.