环境变量
在不更改代码的情况下控制应用程序配置和行为。
Electrond的某些行为受环境变量的控制, 因为它们比命令行标志和应用程序的代码更早初始化。
POSIX shell示例:
$ export ELECTRON_ENABLE_LOGGING=true
$ electron
Windows 控制台示例:
> set ELECTRON_ENABLE_LOGGING=true
> electron
生产环境相关变量
以下环境变量主要用于在打包后的Electron应用运行时使用。
NODE_OPTIONS
Electron 包括对 Node 的 NODE_OPTIONS
的子集的支持。 除与 Chromium 使用 BoringSSL 相抵触的情况外,大多数都得到了支持。
示例:
export NODE_OPTIONS="--no-warnings --max-old-space-size=2048"
不支持的选项是:
--use-bundled-ca
--force-fips
--enable-fips
--openssl-config
--use-openssl-ca
NODE_OPTIONS
are explicitly disallowed in packaged apps, except for the following:
--max-http-header-size
--http-parser
GOOGLE_API_KEY
Geolocation support in Electron requires the use of Google Cloud Platform’s geolocation webservice. To enable this feature, acquire a Google API key and place the following code in your main process file, before opening any browser windows that will make geolocation requests:
process.env.GOOGLE_API_KEY = 'YOUR_KEY_HERE'
By default, a newly generated Google API key may not be allowed to make geolocation requests. To enable the geolocation webservice for your project, enable it through the API library.
N.B. You will need to add a Billing Account to the project associated to the API key for the geolocation webservice to work.
ELECTRON_NO_ASAR
Disables ASAR support. This variable is only supported in forked child processes and spawned child processes that set ELECTRON_RUN_AS_NODE
.
ELECTRON_RUN_AS_NODE
当做普通Node.js进程启动。
In this mode, you will be able to pass cli options to Node.js as you would when running the normal Node.js executable, with the exception of the following flags:
- “—openssl-config”
- “—use-bundled-ca”
- “—use-openssl-ca”,
- “—force-fips”
- “—enable-fips”
These flags are disabled owing to the fact that Electron uses BoringSSL instead of OpenSSL when building Node.js’ crypto
module, and so will not work as designed.
ELECTRON_NO_ATTACH_CONSOLE
Windows
不附加到当前控制台会话。
ELECTRON_FORCE_WINDOW_MENU_BAR
Linux
不使用 Linux 的全局菜单栏。
ELECTRON_TRASH
Linux
Set the trash implementation on Linux. Default is gio
.
Options:
gvfs-trash
trash-cli
kioclient5
kioclient
开发环境相关变量
以下环境变量主要用于开发和调试目的。
ELECTRON_ENABLE_LOGGING
将 Chrome 的内部日志打印到控制台。
ELECTRON_LOG_ASAR_READS
When Electron reads from an ASAR file, log the read offset and file path to the system tmpdir
. The resulting file can be provided to the ASAR module to optimize file ordering.
ELECTRON_ENABLE_STACK_DUMPING
当Electron崩溃时, 将跟踪堆栈输出到控制台。
如果 crashReporter
已经启动了, 则此环境变量将不起作用。
ELECTRON_DEFAULT_ERROR_MODE
Windows
当Electron崩溃时显示 Windows 的崩溃对话框。
如果 crashReporter
已经启动了, 则此环境变量将不起作用。
ELECTRON_OVERRIDE_DIST_PATH
当 electron
包运行时,该变量告知 electron
命令使用指定Electron的构建代替由 npm install
下载的构建。 用法:
export ELECTRON_OVERRIDE_DIST_PATH=/Users/username/projects/electron/out/Testing
Set By Electron
Electron sets some variables in your environment at runtime.
ORIGINAL_XDG_CURRENT_DESKTOP
This variable is set to the value of XDG_CURRENT_DESKTOP
that your application originally launched with. Electron sometimes modifies the value of XDG_CURRENT_DESKTOP
to affect other logic within Chromium so if you want access to the original value you should look up this environment variable instead.