{"id":13774194,"url":"https://github.com/victornpb/rollup-plugin-baked-env","last_synced_at":"2025-03-24T18:32:35.925Z","repository":{"id":38422955,"uuid":"488007221","full_name":"victornpb/rollup-plugin-baked-env","owner":"victornpb","description":"A Rollup Plugin for baking a process.env module inside your code","archived":false,"fork":false,"pushed_at":"2023-02-27T06:59:04.000Z","size":1532,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-15T09:23:55.766Z","etag":null,"topics":["constants","define","env","environment-variables","rollup","rollup-plugin"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/rollup-plugin-baked-env","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/victornpb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"custom":["https://www.buymeacoffee.com/vitim"],"github":null,"patreon":null,"open_collective":null,"ko_fi":"victornpb","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null}},"created_at":"2022-05-02T22:20:58.000Z","updated_at":"2024-02-04T19:17:24.000Z","dependencies_parsed_at":"2023-12-19T01:01:08.923Z","dependency_job_id":"535bd5f8-d4fd-4aeb-b730-b0e30387f8c4","html_url":"https://github.com/victornpb/rollup-plugin-baked-env","commit_stats":{"total_commits":26,"total_committers":2,"mean_commits":13.0,"dds":"0.038461538461538436","last_synced_commit":"21aa694c5c3ecb828b4f217bd9cafbbff14f162f"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":"victornpb/template-library-with-rollup","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victornpb%2Frollup-plugin-baked-env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victornpb%2Frollup-plugin-baked-env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victornpb%2Frollup-plugin-baked-env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/victornpb%2Frollup-plugin-baked-env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/victornpb","download_url":"https://codeload.github.com/victornpb/rollup-plugin-baked-env/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221999249,"owners_count":16914061,"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":["constants","define","env","environment-variables","rollup","rollup-plugin"],"created_at":"2024-08-03T17:01:24.559Z","updated_at":"2024-10-29T06:20:19.842Z","avatar_url":"https://github.com/victornpb.png","language":"JavaScript","funding_links":["https://www.buymeacoffee.com/vitim","https://ko-fi.com/victornpb"],"categories":["Plugins"],"sub_categories":["Modules"],"readme":"# rollup-plugin-baked-env\n\u003c!-- badge --\u003e\n[![LICENSE](https://img.shields.io/github/license/victornpb/rollup-plugin-baked-env?style=flat-square)](LICENSE)\n[![Node](https://img.shields.io/node/v/rollup-plugin-baked-env.svg?style=flat-square)](package.json)\n[![CodeFactor](https://www.codefactor.io/repository/github/victornpb/rollup-plugin-baked-env/badge?style=flat-square)](https://www.codefactor.io/repository/github/victornpb/rollup-plugin-baked-env)\n\n[![Coverage Status](https://img.shields.io/coveralls/victornpb/rollup-plugin-baked-env.svg?style=flat-square)](https://coveralls.io/github/victornpb/rollup-plugin-baked-env)\n[![Travis](https://img.shields.io/travis/victornpb/rollup-plugin-baked-env/master.svg?style=flat-square)](https://travis-ci.org/victornpb/rollup-plugin-baked-env)\n\n[![Version](https://img.shields.io/npm/v/rollup-plugin-baked-env.svg?style=flat-square)](https://www.npmjs.com/package/rollup-plugin-baked-env)\n[![Downloads](https://img.shields.io/npm/dt/rollup-plugin-baked-env.svg?style=flat-square)](https://www.npmjs.com/package/rollup-plugin-baked-env)\n[![](https://img.shields.io/bundlephobia/minzip/tiny-dedent?style=flat-square)](https://www.npmjs.com/package/rollup-plugin-baked-env)\n[![](https://img.shields.io/tokei/lines/github/victornpb/rollup-plugin-baked-env?style=flat-square)](https://www.npmjs.com/package/rollup-plugin-baked-env)\n\u003c!-- endbadge --\u003e\n\n![](https://user-images.githubusercontent.com/3372598/221454014-917d328c-9d88-4fee-b451-42f505a8ca52.jpg)\n\nThis plugin allow you to use environment variables inside your code by importing \"process.env\" as a module. The environment variable will be baked in your code at compile time. Only the variables being used are included in your bundled file.\n\n# Usage Examples\nInside your code you can do something like this:\n\n## Basic usage\n```js\nimport { FOO_BAR } from 'process.env';\n\n// use the variable\nif (FOO_BAR === 'foo') {\n    // do stuff\n}\n```\n\n## Import variable, aliasing it to another name\n```js\nimport { FOO_BAR as myFooBar } from 'process.env';\n\nif (myFooBar) {\n    // code\n}\nelse {\n    // code\n}\n```\n\n## Import multiple variables\n```js\nimport { NODE_ENV, FOO, BAR } from 'process.env';\n\nconsole.log(FOO, BAR);\nif (NODE_ENV === 'production') {\n    // code\n}\n```\n\n## Readability and consistency\nIf you used to plugins like EnvironmentPlugin or DefinePlugin they use find/replace to replace the constants in your source codoe, but reading the code it's unclear where a variable is coming from, also ESLint and prettier thinks those variables are globals, since there's no reference about then anywhere. This fixes the, whithout having to make a whitelist.\n\n## Validation by default\nYour code will fail to compile if the code imports variables that are not set!\n\n\u003cimg width=\"486\" alt=\"image\" src=\"https://user-images.githubusercontent.com/3372598/166487903-fa766449-852b-456c-9509-3b8b3642ec20.png\"\u003e\n\u003cimg width=\"814\" alt=\"image\" src=\"https://user-images.githubusercontent.com/3372598/166487655-a4b15ea2-e53c-4a23-bb9c-ca0de2334b5c.png\"\u003e\n\n\n## Caveats importing all variables\n\nIf you do `import * as env from 'process.env'` never use the `env` variable directly!\nThis will cause rollup to embed ALL environment variables inside your bundle.\n\nWorks fine, but not recommended:\n```js\nimport * as env from 'process.env'; // ✋ AVOID!\n\nif (env.production !== 'production') {\n    console.log('My home directory is ' + env.HOME);\n}\n```\nBecause if you do this, bad things happen:\n```js\nimport * as env from 'process.env'; // ✋ BAD!\n\nconsole.log(env); // 🚫 BAD! (DON'T DO THIS!)\n\nObject.keys(env).filter(/* ... */) // 🚫 BAD! (if you access the env at runtime, it will force rollup to embed everything)\n```\n\n\n# Installation\n\n## [NPM](https://npmjs.com/package/rollup-plugin-baked-env)\n\n    npm install --D rollup-plugin-baked-env\n## [Yarn](https://github.com/yarnpkg/yarn)\n\n    yarn add --dev rollup-plugin-baked-env\n\n# Adding to your project\n\n#### rollup.config.js\n```js\nimport bakedEnv from 'rollup-plugin-baked-env';\n\nexport default {\n    // ...\n    plugins: [\n        bakedEnv(),\n    ],\n};\n```\n\n## Options\n\nbakedEnv(variables, options)\n\n| Parameters            | Description                                                                       | Type    | Default Value   |\n|-----------------------|-----------------------------------------------------------------------------------|---------|-----------------|\n| `variables`           | The variables to be exposed.                                                      | object  | `process.env`   |\n| `options.moduleName`  | The name of the faux module. You can choose another name like 'environment_vars'` | string  | `'process.env'` |\n| `options.preferConst` | Embed variables in the code as const instead of var.                              | boolean | `true`          |\n| `options.compact`     | Generate code without line breaks.                                                | boolean | `false`         |\n| `options.indent`      | The indentation to use in the generated code.                                     | string  | `'\\t'`          |\n\n\n### Options example\n```js\nimport bakedEnv from 'rollup-plugin-baked-env';\n\nconst myVariables = {\n  MY_VAR_1: 'value1',\n  MY_VAR_2: 'value2',\n};\n\nexport default {\n  // ...\n  plugins: [\n    bakedEnv(myVariables, {\n      moduleName: 'enviroment_vars', // expose variables as a module called 'enviroment_vars' example: `import { FOO } from 'enviroment_vars';`\n      preferConst: true,\n      compact: false,\n      indent: '  ',\n    }),\n  ],\n};\n```\n\n## License\n\nThe code is available under the [MIT](LICENSE) license.\n\n## Contributing\n\nWe are open to contributions, see [CONTRIBUTING.md](CONTRIBUTING.md) for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictornpb%2Frollup-plugin-baked-env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvictornpb%2Frollup-plugin-baked-env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictornpb%2Frollup-plugin-baked-env/lists"}