📅  最后修改于: 2020-10-25 10:58:00             🧑  作者: Mango
环境变量控制应用程序的配置和行为,而无需更改代码。某些电子行为受环境变量控制,因为它们的初始化早于命令行标志和应用程序的代码。
电子中编码有两种环境变量-生产变量和发育变量。
以下环境变量旨在在打包的Electron应用程序中的运行时使用。
Sr.No | Variable & Description |
---|---|
1 |
GOOGLE_API_KEY Electron includes a hardcoded API key for making requests to Google’s geocoding webservice. Because this API key is included in every version of Electron, it often exceeds its usage quota. To work around this, you can supply your own Google API key in the environment. Place the following code in your main process file, before opening any browser windows that will make geocoding requests − process.env.GOOGLE_API_KEY = 'YOUR_KEY_HERE' |
2 |
ELECTRON_RUN_AS_NODE Starts the process as a normal Node.js process. |
3 |
ELECTRON_FORCE_WINDOW_MENU_BAR (Linux Only) Do not use the global menu bar on Linux. |
以下环境变量主要用于开发和调试目的。
Sr.No | Variable & Description |
---|---|
1 |
ELECTRON_ENABLE_LOGGING Prints Chrome’s internal logging to the console. |
2 |
ELECTRON_ENABLE_STACK_DUMPING Prints the stack trace to the console when Electron crashes. |
3 |
ELECTRON_DEFAULT_ERROR_MODE Shows the Windows’s crash dialog when Electron crashes. |
要将这些环境变量中的任何一个设置为true,请在控制台中进行设置。例如,如果要启用日志记录,则使用以下命令-
> set ELECTRON_ENABLE_LOGGING=true
$ export ELECTRON_ENABLE_LOGGING=true
请注意,每次重新启动计算机时,都需要设置这些环境变量。如果要避免这样做,请将这些行添加到.bashrc文件中。