.env.vault.local -
Install the standard dotenv package (which now natively supports Vault features in modern versions). npm install dotenv --save Use code with caution. Step 2: Initialize Dotenv Vault Run the initialization command to register your project. npx dotenv-vault@latest new Use code with caution.
执行后,会生成一个加密的 .env.vault 文件,以及一个包含解密密钥的 .env.keys 文件。
In your application entry point (e.g., index.js , main.py , app.rb ), load both vault files. The .env.vault.local should take precedence.
When you encrypt your local variables using the vault CLI (e.g., npx dotenv-vault push ), it generates an encrypted .env.vault file. This file contains all your environment variables, but they are scrambled using AES encryption. .env.vault.local
While the contents are encrypted, the metadata is often plaintext. A typical .env.vault or .env.vault.local file looks like this:
When you run commands like npx dotenv-vault@latest local build , the tool generates the vault files.
: Local overrides and CLI configuration states. .env : Your local plaintext environment variables. Install the standard dotenv package (which now natively
This allows you to see the actual key-value pairs without exposing them in a permanent file. 4. Deployment Strategy
Ensure it is explicitly in your .gitignore :
: An encrypted version of your environment variables. This file is safe to commit to source control because its contents are unreadable without a decryption key. npx dotenv-vault@latest new Use code with caution
在你的 .gitignore 文件中,应该包含以下规则:
NEXT_PUBLIC_FEATURE_X="true"