{"id":27427303,"url":"https://github.com/admirsaheta/dynamic-env","last_synced_at":"2026-04-09T07:05:30.626Z","repository":{"id":274518733,"uuid":"923142410","full_name":"admirsaheta/dynamic-env","owner":"admirsaheta","description":"Manage your environment variables directly from runtime","archived":false,"fork":false,"pushed_at":"2025-01-28T13:33:20.000Z","size":487,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T13:27:20.446Z","etag":null,"topics":["environment","javascript","typescript","vite","web"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@spacier/dynamic-env","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/admirsaheta.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-27T18:00:26.000Z","updated_at":"2025-01-28T13:03:18.000Z","dependencies_parsed_at":"2025-01-27T20:24:51.431Z","dependency_job_id":null,"html_url":"https://github.com/admirsaheta/dynamic-env","commit_stats":null,"previous_names":["admirsaheta/dynamic-env"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/admirsaheta%2Fdynamic-env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/admirsaheta%2Fdynamic-env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/admirsaheta%2Fdynamic-env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/admirsaheta%2Fdynamic-env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/admirsaheta","download_url":"https://codeload.github.com/admirsaheta/dynamic-env/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248884372,"owners_count":21177396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["environment","javascript","typescript","vite","web"],"created_at":"2025-04-14T12:49:48.133Z","updated_at":"2025-12-30T23:05:07.627Z","avatar_url":"https://github.com/admirsaheta.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv style=\"width: 100vw; display: flex; justify-content: center;\"\u003e\n  \u003cimg src=\"https://github.com/user-attachments/assets/17bbc6a4-84c3-44f6-b056-90da4481f5c3\" width=\"600\" height=\"300\" alt=\"Dynamic Env Logo\" /\u003e\n\u003c/div\u003e\n\n# @spacier/dynamic-env\n\nA lightweight utility for managing environment variables in applications, with special support for Vite ( meaning not limited to react ) and Create React App.\n\n## Features\n\n- 🚀 Runtime environment variable injection\n- 🔄 Support for both Vite and Create React App\n- 🛠️ Simple CLI interface\n- 🔒 Type-safe environment variables\n- 📦 Zero runtime dependencies\n\n## Installation\n\n```bash\nnpm install @spacier/dynamic-env\n# or\nyarn add @spacier/dynamic-env\n# or\npnpm add @spacier/dynamic-env\n```\n\n## Usage\n\n### 1. Set up environment variables\n\nCreate a `.env` file in your project root:\n\n```env\nVITE_API_URL=\"https://api.example.com\"\nREACT_APP_API_KEY=\"your-api-key\"\n```\n\n### 2. Configure your application\n\nAdd the environment script to your HTML file:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cscript src=\"/env.js\"\u003e\u003c/script\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cdiv id=\"root\"\u003e\u003c/div\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n### 3. Create a type-safe environment configuration\n\n```typescript\n// env.ts\ndeclare global {\n  interface Window {\n    env: ImportMetaEnv;\n  }\n}\n\ninterface ImportMetaEnv {\n  VITE_API_URL: string;\n  REACT_APP_API_KEY: string;\n  [key: string]: string;\n}\n\nexport const env = {\n  ...import.meta.env,\n  ...window.env,\n} as ImportMetaEnv;\n\nexport default env;\n```\n\n### 4. Use environment variables\n\n```typescript\nimport { env } from './env';\n\nfunction App() {\n  return (\n    \u003cdiv\u003e\n      \u003cp\u003eAPI URL: {env.VITE_API_URL}\u003c/p\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\n## CLI Commands\n\n### Set Environment Variables\n\nInject environment variables into your build:\n\n```bash\nnpx dynamic-env set --dir dist\n```\n\n```bash\nVITE_COLOR=red npx dynamic-env set --dir dist --name env.js\n```\n\nOptions:\n- `--dir, -d`: Build directory path (default: \"./build\")\n- `--name, -n`: Output filename (default: \"env.js\")\n- `--var, -v`: Variable name in window object (default: \"env\")\n\n### Build with Environment Variables\n\nBuild your application with environment variable placeholders:\n\n```bash\nnpx dynamic-env build \"npm run build\"\n```\n\nOptions:\n- `--dotenv`: Enable .env file support (default: true)\n- `--bypass`: Skip environment variable injection\n\n## TypeScript Support\n\nThe library includes built-in TypeScript declarations. No additional setup required.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nMIT\n\n## Author\n\nAdmir Saheta\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadmirsaheta%2Fdynamic-env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadmirsaheta%2Fdynamic-env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadmirsaheta%2Fdynamic-env/lists"}