<h1dotenv-run</h1
dotenv-run is a collection of packages that use dotenv to support loading environment variables from .env files with multiple integrations.
Here are some of the benefits of using dotenv-run:
- ✅ Monorepo ✨: supports monorepo projects with multiple applications.
- ✅ Universal: supports multiple integrations including CLI, Webpack, Rollup, Vite, ESbuild and Angular.
- ✅ TypeScript: supports TS projects with type definitions for process.env and import.meta.env.
- ✅ ESM: supports process.env and import.meta.env in ESM modules.
- ✅ Secure: supports filtering environment variables by prefix.
<h2Integrations</h2
| Integration | Package | Status | | --------------- | ----------------------------------------- | ------ | | CLI | @dotenv-run/cli | ✅ | | Core | @dotenv-run/core | ✅ | | ESBuild | @dotenv-run/esbuild | ✅ | | webpack | @dotenv-run/webpack | ✅ | | Rollup | @dotenv-run/rollup | ✅ | | Vite | @dotenv-run/vite | ✅ | | Rspack | @dotenv-run/rspack | ✅ | | Node.js preload | @dotenv-run/load | ✅ | | Angular | @ngx-env/builder | ✅ |
Quick start
- Quick start
- @dotenv-run/cli
- @dotenv-run/core
- @dotenv-run/esbuild
- @ngx-env/builder
- Testimonials
- Demos
- Quick start
- @dotenv-run/webpack
- @dotenv-run/rollup
- @dotenv-run/vite
- @dotenv-run/rspack
- Credits
- License
Assuming you have the following monorepo structure:
platform
├── apps
│ ├── vite-app
│ ├── ng-app
│ └── esbuild-app
│ │ ├── .env.local # API_BASE=http://localhost:3001
│ │ ├── package.json
│ │ └── webapp.config.mjs
├── libs
│ └── rollup-lib
│ ├── package.json
│ └── rollup.config.mjs├── .env.prod # APIBASE=https://prod.dotenv.run ├── .env # APIUSERS=$APIBASE/api/v1/users;APIAUTH=https://$APIBASE/auth ├── nx.json └── package.json
and the following `dotenv-run` options:
{ "verbose": true, // print debug information "unsecure": true, // display environment variables values "root": "../..", // root directory to search for .env files "environment": "dev", // environment to load (default: NODEENV) "files": [".env"], // .env files to load (default: .env) "prefix": "^API" // prefix to filter environment variables (used with bundlers) }
`dotenv-run` will search and load `.env.*` files located in the root workspace `/home/code/platform` down to the current working directory of the application.
- Root directory: /home/code/platform
- Working directory: /codes/code/platform/apps/esbuild-app
- Files: .env
- Environment: dev
- Environment files:
✔ /home/code/platform/apps/esbuild-app/.env.local ✔ /home/code/platform/.env.dev ✔ /home/code/platform/.env