{"id":14981909,"url":"https://github.com/inokawa/babel-plugin-evaluate-modules","last_synced_at":"2026-02-03T09:01:20.432Z","repository":{"id":65146539,"uuid":"492379866","full_name":"inokawa/babel-plugin-evaluate-modules","owner":"inokawa","description":"A babel plugin to evaluate modules at build-time.","archived":false,"fork":false,"pushed_at":"2023-12-15T08:25:32.000Z","size":166,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-16T18:40:27.253Z","etag":null,"topics":["babel","babel-plugin"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/babel-plugin-evaluate-modules","language":"TypeScript","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/inokawa.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,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["inokawa"]}},"created_at":"2022-05-15T03:42:42.000Z","updated_at":"2025-02-22T16:47:34.000Z","dependencies_parsed_at":"2023-12-15T09:31:21.691Z","dependency_job_id":"c4cc1577-3ef4-4ba8-8c01-dc963ed37a8d","html_url":"https://github.com/inokawa/babel-plugin-evaluate-modules","commit_stats":{"total_commits":19,"total_committers":1,"mean_commits":19.0,"dds":0.0,"last_synced_commit":"70d569d7972034af147a969b6e91703034d17d33"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/inokawa/babel-plugin-evaluate-modules","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inokawa%2Fbabel-plugin-evaluate-modules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inokawa%2Fbabel-plugin-evaluate-modules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inokawa%2Fbabel-plugin-evaluate-modules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inokawa%2Fbabel-plugin-evaluate-modules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inokawa","download_url":"https://codeload.github.com/inokawa/babel-plugin-evaluate-modules/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inokawa%2Fbabel-plugin-evaluate-modules/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29039341,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T08:41:49.363Z","status":"ssl_error","status_checked_at":"2026-02-03T08:40:19.255Z","response_time":96,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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"],"created_at":"2024-09-24T14:04:28.083Z","updated_at":"2026-02-03T09:01:20.416Z","avatar_url":"https://github.com/inokawa.png","language":"TypeScript","readme":"# babel-plugin-evaluate-modules\n\n![npm](https://img.shields.io/npm/v/babel-plugin-evaluate-modules) ![check](https://github.com/inokawa/babel-plugin-evaluate-modules/workflows/check/badge.svg)\n\nA babel plugin to evaluate modules at build-time.\n\n## Why?\n\nI wanted to evaluate some functions and calculations in build process that didn't need to run at runtime, to remove the modules themselves from the bundle to reduce its size.\n\n- [babel-plugin-preval](https://github.com/kentcdodds/babel-plugin-preval) and [babel-plugin-codegen](https://github.com/kentcdodds/babel-plugin-codegen) only supports CommonJS not ES Modules, and the evaluation does not run in a sandbox.\n\n- [babel-plugin-polished](https://github.com/styled-components/babel-plugin-polished) only supports [polished](https://github.com/styled-components/polished) and only handles simple syntaxes.\n\n- [babel-plugin-inline-constants](https://github.com/wooorm/babel-plugin-inline-constants) only handles constants inlining.\n\n## Setup\n\n```sh\nnpm install babel-plugin-evaluate-modules\n```\n\n## Usage\n\n### Evaluate modules in node_modules\n\n```ts\n// babel.config.js\nmodule.exports = {\n  plugins: [[\"babel-plugin-evaluate-modules\", { name: \"polished\" }]],\n};\n\n// App.js\nimport { rgba } from \"polished\";\n\nconst val = \"blue\";\nconst obj = {\n  color: \"#123456\",\n  red: \"red\",\n};\n\nconst a = rgba(val, 0.5); // const a = \"rgba(0,0,255,0.5)\";\nconst b = rgba(obj[\"color\"], 0.5); // const b = \"rgba(18,52,86,0.5)\";\nconst c = rgba(obj.red, 0.5); // const c = \"rgba(255,0,0,0.5)\";\n```\n\n### Evaluate local modules\n\n```ts\n// babel.config.js\nmodule.exports = {\n  plugins: [[\"babel-plugin-evaluate-modules\", { name: /\\/constants\\// }]],\n};\n\n// constants/foo.js\nexport const foo = 2 * 7;\nexport const bar = \"bar\" + \"baz\";\n\n// App.js\nimport { foo, bar } from \"./constants/foo.js\";\nconst fooVal = foo; // const fooVal = 14;\nconst barVal = bar; // const barVal = \"barbaz\";\n```\n\n## Contribute\n\nAll contributions are welcome.\nIf you find a problem, feel free to create an [issue](https://github.com/inokawa/babel-plugin-evaluate-modules/issues) or a [PR](https://github.com/inokawa/babel-plugin-evaluate-modules/pulls).\n\n### Making a Pull Request\n\n1. Fork this repo.\n2. Run `npm install`.\n3. Commit your fix.\n4. Add tests to cover your fix.\n5. Make a PR and confirm all the CI checks passed.\n","funding_links":["https://github.com/sponsors/inokawa"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finokawa%2Fbabel-plugin-evaluate-modules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finokawa%2Fbabel-plugin-evaluate-modules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finokawa%2Fbabel-plugin-evaluate-modules/lists"}