如何从 electron-builder yaml 配置文件中的 .env 文件中读取?

How to read from .env file in electron-builder yaml config file?

我是电子新手。我有一个包裹在电子中的 angular 应用程序,我想使用 electron-builder 构建 package/installer。我正在使用 electron-builder-config.yaml 文件来构建安装程序。

我想知道如何将 .env 环境文件中的值读入 electron-builder-config.yaml 文件?

我想设置命令electron-builder -w --publish always -c ./builder-config.yaml生成的包的版本。

我确实尝试使用 buildVersion 属性 但问题是有一个 installer.nsh 文件需要 运行 作为 nsis 安装程序的一部分来设置路径该文件使用 ${version}.

electron-builder-config.yaml

中环境变量的使用很少documentation

这是我的 electron-builder-config.yaml

directories:
  output: ./dist/electron
  buildResources: ./electron/build
  app: ''
electronVersion: X.Y.Z
appId:  com.sample.app
copyright: "Copyright © 2020 ${author}"
productName: TestApp
forceCodeSigning: true
artifactName: "${productName}-${os}-${version}.${ext}"
files:
  - "**/dist/electron/*"
  - "**/electron/*"
asar: true
compression: maximum
mac:
  category: public.app-category.reference
  icon: "./icon-file.icns"
  publish: [{
      "provider": "generic",
      "url": "http://localhost:8080"
  }]
dmg:
  background: "./build/sample.jpg"
  icon: "./build/nw.icns"
  iconSize: 96
  contents:
    - x: 650
      y: 230
      type: link
      path: /Applications
    - x: 350
      y: 230
      type: file
win:
  cscLink: "./somelink.pfx"
  cscKeyPassword: "XXXXXX"
  target: [nsis]
  icon: "./appinfo.ico"
  publish: [{
      "provider": "generic",
      "url": "http://localhost:8080"
  }]
msi:
  shortcutName: "TestApp - ${version}"
  createDesktopShortcut: true
  createStartMenuShortcut: true
nsis:
  include: "./installer.nsh"
  installerIcon: "./appinfo.ico"
  uninstallerIcon: "./appinfo.ico"
  packElevateHelper: true
  allowToChangeInstallationDirectory: true
  perMachine: true
  oneClick: false
  createDesktopShortcut: true
  createStartMenuShortcut: true
  shortcutName: "TestApp - ${version}"
  guid: "someguid"
npmRebuild: true
nodeGypRebuild: false

此外,我对宏 ${ext} 不太确定。这个 electron-builder-config.yaml 文件从哪里获取这个值?即使在documentation for file-macros,版本也没有明确的定义。有什么建议吗?

我明白了。如果其他人正在寻找这个问题的答案,这就是我的工作方式。

第 1 步:package.json 所在的根级别创建一个名为 electron-builder.env 的文件。请确保将文件名保留为 electron-builder.env

第 2 步:electron-builder.env 文件中定义您想要的变量,例如 ELECTRON_BUILD_VERSION=99.99

第 3 步: 在您的 builder-config.yaml 文件中,使用语法 {env.ELECTRON_BUILD_VERSION}[ 访问环境变量=16=]

给你。玩得开心。快乐编码