如何最好地将文件打包到电子的基本安装目录中

How best to package files on base install directory of electron

我一直在尝试制作一个依赖于第三方可执行文件的电子应用程序。每当我尝试捆绑应用程序时,可执行文件都会以 asar 格式与应用程序的其余部分捆绑在一起,从而无法从 electron\node 环境外部进行访问。

我的问题是我应该如何设置我的环境或构建配置以实现第三方可执行文件位于已安装应用程序的根目录中的安装?

PS:我正在使用 electron-builder 和一个双 package.json 格式,我得到了一个 成功构建减去此警告。

这是我的构建配置

"build": {
    "appId": "com.toutici.asd",
    "asar": true,
    "directories": {
      "app": "./app",
      "buildResources": "./build",
      "output": "./dist"
    },
    "electronDownload": {
      "cache": ".electron",
      "verifyChecksum": true
    },
    "electronVersion": "1.7.11",
    "fileAssociations": {
      "ext": "asd",
      "icon": "./www/assets/icon/win/icon.ico"
    },
    "productName": "Android SMS Delimiter",
    "mac": {
      "category": "public.app-category.productivity",
      "target": [
        "dmg",
        "mas"
      ],
      "icon": "./build/icon.icns"
    },
    "dmg": {
      "contents": [
        {
          "x": 110,
          "y": 150
        },
        {
          "x": 240,
          "y": 150,
          "type": "link",
          "path": "/Applications"
        }
      ]
    },
    "deb": {
      "compression": "gz",
      "icon": "./build/background.png"
    },
    "linux": {
      "target": [
        "AppImage",
        "apk",
        "deb",
        "rpm",
        "snap",
        "tar.gz",
        "zip"
      ]
    },
    "win": {
      "target": [
        {
          "target": "nsis",
          "arch": [
            "ia32"
          ]
        }
      ],
      "icon": "build/icon.ico"
    },
    "nsis": {
      "oneClick": true,
      "perMachine": true,
      "allowElevation": true,
      "allowToChangeInstallationDirectory": false,
      "createDesktopShortcut": true,
      "runAfterFinish": true,
      "installerIcon": "./build/icon.ico"
    },
    "portable": {
      "requestExecutionLevel": "user"
    },
    "squirrelWindows": {
      "iconUrl": "./build/icon.ico",
      "loadingGif": "./build/install-spinner.gif",
      "msi": true
    }
  }

添加

extraFiles

config 属性 到 electron-builder.json 好像可以解决问题。

例如:

  "extraFiles": [
      {
         "from": "../../CHANGELOG.md",
          "to": "."
      }
    ],

另见电子配置文档:https://www.electron.build/configuration/contents#extrafiles