简体   繁体   English

环境变量来更改project.json中的应用程序名称并设置运行时变量?

[英]Env vars to change app name in project.json and set runtime vars?

I need to generate two apps from the same codebase (eg "pro" and "lite" versions). 我需要从同一代码库(例如“ pro”和“ lite”版本)生成两个应用程序。 There are a lot of questions here about this but none I found involve node or electron . 这里有很多问题,但是我发现没有一个涉及nodeelectron

I have only used env in development in very simple ways and after searching around, I haven't seen any mention of being able to use them in a deployed application. 我只是以非常简单的方式在开发中使用了env ,并且在四处搜索之后,我还没有提到能够在已部署的应用程序中使用它们的情况。

So two tasks: 因此有两个任务:
1. Changing the name of the app 1.更改应用名称

So, using the package.json file with electron builder , I've tried to change the productName like this: 因此,将package.json文件与electron builder ,我试图像这样更改productName

  "productName": process.env.APP_NAME,
  "main": "main.js",
  "scripts": {
    "package-mac": process.env.APP_NAME='Bingo' electron-packager . --overwrite  --platform=darwin --arch=x64  --prune=true --out=release-builds"
}

But that didn't work. 但这没有用。 Also saw this construction but it also didn't work: 还看到了这种构造,但也没有用:

  "productName": '${process.env.APP_NAME}',

Am I on the wrong track here? 我在这里走错了路吗?

2. Vars for use at runtime 2.运行时使用的变量
To do the "pro" & "lite" thing, I need at least a flag to know how to configure things. 为了做“专业”和“精简”的事情,我至少需要一个标志来知道如何配置。
Are env vars in anyway suitable for this? 反正env vars适合吗?

I guess if I am able to change the app name, I can access that at runtime but it seems like I am missing something important with all this. 我想如果我能够更改应用程序名称,则可以在运行时访问该名称,但似乎所有这些东西都缺少重要的内容。

Using dot-json , you can have npm scripts like: 使用dot-json ,您可以拥有如下npm脚本:

  "productName": "Bingo",
  "main": "main.js",
  "scripts": {
    "package-mac": "echo $APP_NAME; dot-json package.json productName $APP_NAME --indent 2; electron-packager . --overwrite  --platform=darwin --arch=x64  --prune=true --out=release-builds"
  }

In Terminal, maybe, you can run 在终端中,也许您可​​以运行

 $ APP_NAME='Bingo Pro' npm run package-mac

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM