{"id":17786160,"url":"https://github.com/dcodeio/esm2umd","last_synced_at":"2025-10-09T18:12:37.850Z","repository":{"id":37012603,"uuid":"269223337","full_name":"dcodeIO/esm2umd","owner":"dcodeIO","description":"Transforms ESM to UMD, i.e. to use ESM by default with UMD as a legacy fallback.","archived":false,"fork":false,"pushed_at":"2025-02-18T19:45:23.000Z","size":32,"stargazers_count":6,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-15T23:32:09.996Z","etag":null,"topics":["commonjs","esm","esmodules","javascript","umd"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"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/dcodeIO.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"dcodeIO"}},"created_at":"2020-06-04T00:27:12.000Z","updated_at":"2025-02-28T16:32:06.000Z","dependencies_parsed_at":"2025-02-17T17:37:52.087Z","dependency_job_id":null,"html_url":"https://github.com/dcodeIO/esm2umd","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcodeIO%2Fesm2umd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcodeIO%2Fesm2umd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcodeIO%2Fesm2umd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dcodeIO%2Fesm2umd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dcodeIO","download_url":"https://codeload.github.com/dcodeIO/esm2umd/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243830912,"owners_count":20354848,"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":["commonjs","esm","esmodules","javascript","umd"],"created_at":"2024-10-27T09:04:55.147Z","updated_at":"2025-10-09T18:12:32.817Z","avatar_url":"https://github.com/dcodeIO.png","language":"JavaScript","readme":"# esm2umd\n\nTransforms ESM to UMD, i.e. to use ESM by default with UMD as a legacy fallback.\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/dcodeIO/esm2umd/test.yml?branch=main\u0026label=test\u0026logo=github)](https://github.com/dcodeIO/esm2umd/actions/workflows/test.yml) [![Publish Status](https://img.shields.io/github/actions/workflow/status/dcodeIO/esm2umd/publish.yml?branch=main\u0026label=publish\u0026logo=github)](https://github.com/dcodeIO/esm2umd/actions/workflows/publish.yml) [![npm](https://img.shields.io/npm/v/esm2umd.svg?label=npm\u0026color=007acc\u0026logo=npm)](https://www.npmjs.com/package/esm2umd)\n\n## Usage\n\n```\n$\u003e npm install --save-dev esm2umd\n```\n\n```\nnpx esm2umd MyModule esmFile.js \u003e umdFile.js\n```\n\n`MyModule` is used as the name of the vanilla JS global.\n\nIf the module has a `default` export, it is transformed to a whole-module export.\n\n## API\n\n```js\nimport esm2umd from \"esm2umd\";\n\nconst esmCode = \"...\";\nconst umdCode = esm2umd(\"ModuleName\", esmCode);\n```\n\n## Examples\n\nCommon outline of a hybrid module with legacy fallback, either exporting a class or a namespace:\n\n**package.json**\n\n```json\n{\n  \"type\": \"module\",\n  \"main\": \"./umd/index.js\",\n  \"types\": \"./umd/index.d.ts\",\n  \"exports\": {\n    \".\": {\n      \"import\": {\n        \"types\": \"./index.d.ts\",\n        \"default\": \"./index.js\"\n      },\n      \"require\": {\n        \"types\": \"./umd/index.d.ts\",\n        \"default\": \"./umd/index.js\"\n      }\n    }\n  },\n  \"scripts\": {\n    \"build\": \"npx esm2umd MyModule index.js \u003e umd/index.js \u0026\u0026 cp types.d.ts umd/types.d.ts\"\n  }\n}\n```\n\n**umd/package.json**\n\n```json\n{\n  \"type\": \"commonjs\"\n}\n```\n\n**.gitignore**\n\n```\numd/index.js\numd/types.d.ts\n```\n\n### Class export\n\nAs used by [long.js](https://github.com/dcodeIO/long.js):\n\n**index.d.ts**\n\n```ts\nimport { MyClass } from \"./types.js\";\nexport default MyClass;\n```\n\n**types.d.ts**\n\n```ts\nexport declare class MyClass {\n  // ...\n}\n```\n\n**umd/index.d.ts**\n\n```ts\nimport { MyClass } from \"./types.js\";\nexport = MyClass;\nexport as namespace MyClass;\n```\n\n**umd/types.d.ts**\n\nCopy of types.d.ts.\n\n### Namespace export\n\nAs used by [bcrypt.js](https://github.com/dcodeIO/bcrypt.js):\n\n**index.d.ts**\n\n```ts\nimport * as myNamespace from \"./types.js\";\nexport * from \"./types.js\";\nexport default myNamespace;\n```\n\n**types.d.ts**\n\n```ts\nexport declare function myFunction(): void;\n// ...\n```\n\n**umd/index.d.ts**\n\n```ts\nimport * as myNamespace from \"./types.js\";\nexport = myNamespace;\nexport as namespace myNamespace;\n```\n\n**umd/types.d.ts**\n\nCopy of types.d.ts.\n\n## Building\n\nBuilding the UMD fallback:\n\n```\n$\u003e npm run build\n```\n\nRunning the [tests](./tests):\n\n```\n$\u003e npm test\n```\n","funding_links":["https://github.com/sponsors/dcodeIO"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcodeio%2Fesm2umd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdcodeio%2Fesm2umd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcodeio%2Fesm2umd/lists"}