问题描述
我需要从相同的代码库(例如"pro"和"lite"版本)生成两个应用.这里有很多问题,但我发现没有一个涉及 node
或 electron
.
I need to generate two apps from the same codebase (e.g. "pro" and "lite" versions). There are a lot of questions here about this but none I found involve node
or electron
.
我仅以非常简单的方式在开发中使用过 env
,并且在四处搜寻之后,我再也没有提到能够在已部署的应用程序中使用它们的情况.
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.
所以有两个任务:
1.更改应用名称
因此,将 package.json
文件与 electron builder
结合使用,我试图像这样更改 productName
:
So, using the package.json
file with electron builder
, I've tried to change the productName
like this:
"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}',
我在这里走错了路吗?
2.在运行时使用的变量
做亲"&轻型"事物,我至少需要一个标志才能知道如何配置事物.
反过来, env
vars是否适合吗?
2. Vars for use at runtime
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?
我想我是否能够更改应用程序名称,我可以在运行时访问它,但似乎所有这些东西都缺少重要的内容.
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.
推荐答案
使用 dot-json ,您可以使用npm脚本,例如:
Using dot-json, you can have npm scripts like:
"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
这篇关于Env vars更改project.json中的应用程序名称并设置运行时vars?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!