{"id":13724939,"url":"https://github.com/wooorm/babel-plugin-inline-constants","last_synced_at":"2025-04-19T11:55:47.076Z","repository":{"id":62354731,"uuid":"319054337","full_name":"wooorm/babel-plugin-inline-constants","owner":"wooorm","description":"Babel plugin to inline constants","archived":false,"fork":false,"pushed_at":"2024-09-02T15:40:56.000Z","size":92,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T04:06:03.171Z","etag":null,"topics":["babel","constant","inline","json","plugin"],"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/wooorm.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":"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,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"wooorm"}},"created_at":"2020-12-06T14:36:20.000Z","updated_at":"2025-04-06T18:49:34.000Z","dependencies_parsed_at":"2024-10-20T15:38:41.450Z","dependency_job_id":null,"html_url":"https://github.com/wooorm/babel-plugin-inline-constants","commit_stats":{"total_commits":40,"total_committers":1,"mean_commits":40.0,"dds":0.0,"last_synced_commit":"208742e06e028e8df457df373c950ef76428fafb"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fbabel-plugin-inline-constants","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fbabel-plugin-inline-constants/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fbabel-plugin-inline-constants/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Fbabel-plugin-inline-constants/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wooorm","download_url":"https://codeload.github.com/wooorm/babel-plugin-inline-constants/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249689960,"owners_count":21311307,"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":["babel","constant","inline","json","plugin"],"created_at":"2024-08-03T01:02:07.449Z","updated_at":"2025-04-19T11:55:47.049Z","avatar_url":"https://github.com/wooorm.png","language":"JavaScript","funding_links":["https://github.com/sponsors/wooorm"],"categories":["JavaScript"],"sub_categories":[],"readme":"# babel-plugin-inline-constants\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n\nBabel plugin to inline constants in code.\n\n## Contents\n\n* [What is this?](#what-is-this)\n* [When should I use this?](#when-should-i-use-this)\n* [Install](#install)\n* [Use](#use)\n* [API](#api)\n  * [`inlineConstants`](#inlineconstants)\n* [Types](#types)\n* [Compatibility](#compatibility)\n* [Security](#security)\n* [Related](#related)\n* [Contribute](#contribute)\n* [License](#license)\n\n## What is this?\n\nThis package is a [Babel][] plugin to inline constants in code.\n\n## When should I use this?\n\nThis package is useful because gzip likes repeated patterns (such as using\nmagic numbers or strings multiple times), whereas looking things up in objects\nis easier to develop with.\n“Constants” here are specific files that are imported or required which contain\nprimitives (numbers, strings, booleans, null).\n\nAn example is `micromark`, which is a complex state machine that uses a lot of\nconstants.\nDeveloping with those constants exported from a file, rather than inline, is\neasier.\nShipping those inlines helps with bundle size.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 14.14+, 16.0+), install with [npm][]:\n\n```sh\nnpm install babel-plugin-inline-constants\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport inlineConstants from 'https://esm.sh/babel-plugin-inline-constants@4'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import inlineConstants from 'https://esm.sh/babel-plugin-inline-constants@4?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\nFirst, this plugin must be configured with a `modules`, so in a `.babelrc` or\nso, do:\n\n```json\n{\n  \"plugins\": [[\"babel-plugin-inline-constants\", {\"modules\": \"./math.js\"}]]\n}\n```\n\n…then, our module `math.js`:\n\n```js\nexport const pi = 3.14\n```\n\n…and `example.js`:\n\n```js\nimport {pi} from './math.js'\n\nconsole.log('one pi:', pi)\nconsole.log('two pi:', 2 * pi)\nconsole.log('pi pi:', pi * pi)\n```\n\n…now running Babel:\n\n```sh\nbabel example.js\n```\n\nYields:\n\n```js\nconsole.log('one pi:', 3.14);\nconsole.log('two pi:', 2 * 3.14);\nconsole.log('pi pi:', 3.14 * 3.14);\n```\n\n## API\n\nThis package does not export identifiers.\nThe default export is `inlineConstants`\n\n### `inlineConstants`\n\nBabel plugin to inline constants in code.\nSee [Babel’s documentation][babel-plugins] on how to use Babel plugins.\n\nThis plugin must be configured with a `modules` array.\nValues in this array are the same as the `x` in `import y from x`, and resolve\nfrom the current working directory that babel is running in.\nWhen these modules are then used in code, their values are inlined.\nSo, if you are going to inline a file from `node_modules` such as\n[`charcodes`][charcodes], you can use `modules: ['charcodes']`.\nESM (`import`) and CJS (`require`) are supported.\n\n\u003e ⚠️ **Danger**: modules to be inlined are evaluated with Node, so only use\n\u003e this plugin if you completely trust your code.\n\n\u003e 👉 **Note**: PRs welcome to make this rather experimental project better\n\n##### `options`\n\nConfiguration (required).\n\n###### `options.modules`\n\nList of modules to inline (`string|Array\u003cstring\u003e`).\n\n###### `options.ignoreModuleNotFound`\n\nIgnore the error when modules cannot be found (`boolean`, default: `false`).\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional type `Options`.\n\n## Compatibility\n\nThis package is at least compatible with all maintained versions of Node.js.\nAs of now, that is Node.js 18+.\nIt also works in Deno and modern browsers.\n\n## Security\n\nThis package is safe assuming you trust the code you use.\n\n## Related\n\n* [`babel-plugin-undebug`](https://github.com/wooorm/babel-plugin-undebug)\n  — remove `debug`\n\n## Contribute\n\nYes please!\nSee [How to Contribute to Open Source][contribute].\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/wooorm/babel-plugin-inline-constants/workflows/main/badge.svg\n\n[build]: https://github.com/wooorm/babel-plugin-inline-constants/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/babel-plugin-inline-constants.svg\n\n[coverage]: https://codecov.io/github/wooorm/babel-plugin-inline-constants\n\n[downloads-badge]: https://img.shields.io/npm/dm/babel-plugin-inline-constants.svg\n\n[downloads]: https://www.npmjs.com/package/babel-plugin-inline-constants\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esmsh]: https://esm.sh\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[typescript]: https://www.typescriptlang.org\n\n[contribute]: https://opensource.guide/how-to-contribute/\n\n[babel]: https://babeljs.io\n\n[babel-plugins]: https://babeljs.io/docs/plugins\n\n[charcodes]: https://github.com/xtuc/charcodes\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Fbabel-plugin-inline-constants","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwooorm%2Fbabel-plugin-inline-constants","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Fbabel-plugin-inline-constants/lists"}