最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin7浏览0评论

I am new to electron. I have an angular application wrapped in electron that I want to build the package/installer using electron-builder. I am using electron-builder-config.yaml file to build the installer.

I would like to know how do I read values from .env environment file into electron-builder-config.yaml file ?

I want to set the version of the package that is generated by mand electron-builder -w --publish always -c ./builder-config.yaml.

I did try using buildVersion property but the problem is that there is an installer.nsh file that needs to run as part of nsis installer to set the path and that file uses ${version}.

There is very little documentation on environment variables usage in electron-builder-config.yaml

Here is my electron-builder-config.yaml

directories:
  output: ./dist/electron
  buildResources: ./electron/build
  app: ''
electronVersion: X.Y.Z
appId:  .sample.app
copyright: "Copyright © 2020 ${author}"
productName: TestApp
forceCodeSigning: true
artifactName: "${productName}-${os}-${version}.${ext}"
files:
  - "**/dist/electron/*"
  - "**/electron/*"
asar: true
pression: 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

Also, I am not sure about the macro ${ext}. From where does this electron-builder-config.yaml file is picking up this value ? Even in the documentation for file-macros, the version does not have the clear definition. Any suggestions ?

I am new to electron. I have an angular application wrapped in electron that I want to build the package/installer using electron-builder. I am using electron-builder-config.yaml file to build the installer.

I would like to know how do I read values from .env environment file into electron-builder-config.yaml file ?

I want to set the version of the package that is generated by mand electron-builder -w --publish always -c ./builder-config.yaml.

I did try using buildVersion property but the problem is that there is an installer.nsh file that needs to run as part of nsis installer to set the path and that file uses ${version}.

There is very little documentation on environment variables usage in electron-builder-config.yaml

Here is my electron-builder-config.yaml

directories:
  output: ./dist/electron
  buildResources: ./electron/build
  app: ''
electronVersion: X.Y.Z
appId:  .sample.app
copyright: "Copyright © 2020 ${author}"
productName: TestApp
forceCodeSigning: true
artifactName: "${productName}-${os}-${version}.${ext}"
files:
  - "**/dist/electron/*"
  - "**/electron/*"
asar: true
pression: 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

Also, I am not sure about the macro ${ext}. From where does this electron-builder-config.yaml file is picking up this value ? Even in the documentation for file-macros, the version does not have the clear definition. Any suggestions ?

Share Improve this question asked Jul 20, 2020 at 17:48 The mentalist CoderThe mentalist Coder 3621 gold badge6 silver badges21 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 13

I got it figured out. In case someone else is looking for the answer to this question, here is how I got it working.

Step 1: Create a file by the name electron-builder.env at the root level where your package.json resides. Please make sure that you keep the file name as electron-builder.env

Step 2: Define the variables that you would like to inside the electron-builder.env file, for example ELECTRON_BUILD_VERSION=99.99

Step 3: Inside your builder-config.yaml file, access the environment variable with the syntax {env.ELECTRON_BUILD_VERSION}

There you go. Have fun. Happy Coding

发布评论

评论列表(0)

  1. 暂无评论