Use Vite's
loadEnvon the command-line.
Utilizing Vite's loadEnv function, this CLI tool loads .env files and spawns a child-process with access to the exposed environment variables. This is useful when you want to adopt Vite's mode handling with other tools.
Features
- loads
.envrelevant to mode - filters prefixed environment variables, e.g.
VITE_ - expands environment variables
# npm
npm install loadenv-cli
# JSR
deno add jsr:@idleberg/loadenv-cliNote
Before you read on, make sure you have a basic understanding of Vite's concept of Environment Variables and Modes.
Examples
# Use production .env with Playwright
npx loadenv --mode production playwright test
# Only pass prefixed environment variables
npx loadenv --mode production --prefix VITE_ playwright test
# Pass arguments to Playwright
npx loadenv --mode production --prefix VITE_ playwright test -- --uiSee loadenv --help for all available options.
All of the Node.js examples are valid as long as you substitute npx with bunx.
For ease of use, it's recommended to create tasks in your deno.json file:
Warning
The following example is a simplied for brevity. You likely want to define fine-grained permissions according to your needs.
Example
{
"tasks": {
"test": "deno run -A jsr:@idleberg/loadenv-cli --mode production npm:playwright test"
}
}If this project is not for you, maybe these alternatives suit you better:
This work is licensed under The MIT License.