Skip to content

idleberg/loadenv-cli

Repository files navigation

loadenv-cli

Use Vite's loadEnv on the command-line.

License Version: npm Version: jsr GitHub branch check runs

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 .env relevant to mode
  • filters prefixed environment variables, e.g. VITE_
  • expands environment variables

Installation 💿

# npm
npm install loadenv-cli

# JSR
deno add jsr:@idleberg/loadenv-cli

Usage 🚀

Note

Before you read on, make sure you have a basic understanding of Vite's concept of Environment Variables and Modes.

Node.js

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 -- --ui

See loadenv --help for all available options.

Bun

All of the Node.js examples are valid as long as you substitute npx with bunx.

Deno

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"
	}
}

Related 👫

If this project is not for you, maybe these alternatives suit you better:

License ©️

This work is licensed under The MIT License.

About

Use Vite's loadEnv for CLI

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 2

  •  
  •