{"id":15287819,"url":"https://github.com/tusbar/babel-plugin-dotenv-import","last_synced_at":"2025-08-17T20:10:16.175Z","repository":{"id":26338510,"uuid":"108319638","full_name":"tusbar/babel-plugin-dotenv-import","owner":"tusbar","description":"Load environment variables using import statements.","archived":false,"fork":false,"pushed_at":"2023-12-06T19:35:14.000Z","size":2816,"stargazers_count":78,"open_issues_count":8,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-08T21:57:13.163Z","etag":null,"topics":["babel","babel-plugin","dotenv","environment-variables"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tusbar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-10-25T20:01:42.000Z","updated_at":"2025-04-24T14:33:03.000Z","dependencies_parsed_at":"2023-12-17T19:49:50.832Z","dependency_job_id":null,"html_url":"https://github.com/tusbar/babel-plugin-dotenv-import","commit_stats":{"total_commits":309,"total_committers":10,"mean_commits":30.9,"dds":0.56957928802589,"last_synced_commit":"04a3ad8b0c887306ccf65d0203a6370d0555dc2e"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/tusbar/babel-plugin-dotenv-import","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tusbar%2Fbabel-plugin-dotenv-import","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tusbar%2Fbabel-plugin-dotenv-import/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tusbar%2Fbabel-plugin-dotenv-import/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tusbar%2Fbabel-plugin-dotenv-import/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tusbar","download_url":"https://codeload.github.com/tusbar/babel-plugin-dotenv-import/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tusbar%2Fbabel-plugin-dotenv-import/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270899582,"owners_count":24664720,"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","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["babel","babel-plugin","dotenv","environment-variables"],"created_at":"2024-09-30T15:38:05.442Z","updated_at":"2025-08-17T20:10:16.149Z","avatar_url":"https://github.com/tusbar.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# babel-plugin-dotenv-import\n\n\u003e Load environment variables using `import` statements.\n\n[![npm version](https://badgen.net/npm/v/babel-plugin-dotenv-import)](https://www.npmjs.com/package/babel-plugin-dotenv-import)\n[![codecov](https://badgen.net/codecov/c/github/tusbar/babel-plugin-dotenv-import)](https://codecov.io/gh/tusbar/babel-plugin-dotenv-import)\n[![XO code style](https://badgen.net/badge/code%20style/XO/cyan)](https://github.com/xojs/xo)\n\n## CI\n\n[![Tests](https://github.com/tusbar/babel-plugin-dotenv-import/actions/workflows/tests.yml/badge.svg)](https://github.com/tusbar/babel-plugin-dotenv-import/actions/workflows/tests.yml)\n[![Release](https://github.com/tusbar/babel-plugin-dotenv-import/actions/workflows/release.yml/badge.svg)](https://github.com/tusbar/babel-plugin-dotenv-import/actions/workflows/release.yml)\n\n## Installation\n\n```sh\n$ npm install babel-plugin-dotenv-import\n```\n\n## Usage\n\n**.babelrc**\n\n```json\n{\n  \"plugins\": [\n    [\"dotenv-import\", {\n      \"moduleName\": \"@env\",\n      \"path\": \".env\",\n      \"blocklist\": null,\n      \"allowlist\": null,\n      \"safe\": false,\n      \"allowUndefined\": false\n    }]\n  ]\n}\n```\n\n**.env**\n\n```dosini\nAPI_URL=https://api.example.org\nAPI_TOKEN=\n```\n\nIn **users.js**\n\n```js\nimport {API_URL, API_TOKEN} from \"@env\"\n\nfetch(`${API_URL}/users`, {\n  headers: {\n    'Authorization': `Bearer ${API_TOKEN}`\n  }\n})\n```\n\n## Allow and block lists\n\nIt is possible to limit the scope of env variables that will be imported by specifying a `allowlist` and/or a `blocklist` as an array of strings.\n\n```json\n{\n  \"plugins\": [\n    [\"dotenv-import\", {\n      \"blocklist\": [\n        \"GITHUB_TOKEN\"\n      ]\n    }]\n  ]\n}\n```\n\n```json\n{\n  \"plugins\": [\n    [\"dotenv-import\", {\n      \"allowlist\": [\n        \"API_URL\",\n        \"API_TOKEN\"\n      ]\n    }]\n  ]\n}\n```\n\n## Safe mode\n\nEnable safe mode to only allow environment variables defined in the `.env` file. This will completely ignore everything that is already defined in the environment.\n\nThe `.env` file has to exist.\n\n```json\n{\n  \"plugins\": [\n    [\"dotenv-import\", {\n      \"safe\": true\n    }]\n  ]\n}\n```\n\n## Allow undefined\n\nAllow importing undefined variables, their value will be `undefined`.\n\n```json\n{\n  \"plugins\": [\n    [\"dotenv-import\", {\n      \"allowUndefined\": true\n    }]\n  ]\n}\n```\n\n```js\nimport {UNDEFINED_VAR} from '@env'\n\nconsole.log(UNDEFINED_VAR === undefined) // true\n```\n\nWhen `false` (default behavior), an error will be thrown.\n\n## Caveats\n\nWhen using with [`babel-loader`](https://github.com/babel/babel-loader) with caching enabled you will run into issues where environment changes won’t be picked up.\nThis is due to the fact that `babel-loader` computes a `cacheIdentifier` that does not take your environment into account.\n\nYou can easily clear the cache:\n\n```shell\nrm -rf node_modules/.cache/babel-loader/*\n```\n\nOr you can override the default `cacheIdentifier` to include some of your environment variables.\n\n## Credits\n\nBased on [David Chang](https://github.com/zetachang)’s works on [babel-plugin-dotenv](https://github.com/zetachang/react-native-dotenv/tree/master/babel-plugin-dotenv).\n\n## Miscellaneous\n\n```\n    ╚⊙ ⊙╝\n  ╚═(███)═╝\n ╚═(███)═╝\n╚═(███)═╝\n ╚═(███)═╝\n  ╚═(███)═╝\n   ╚═(███)═╝\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftusbar%2Fbabel-plugin-dotenv-import","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftusbar%2Fbabel-plugin-dotenv-import","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftusbar%2Fbabel-plugin-dotenv-import/lists"}