{"id":19856849,"url":"https://github.com/polymer/koa-esm-transform","last_synced_at":"2025-08-03T00:40:33.053Z","repository":{"id":47977108,"uuid":"193796592","full_name":"Polymer/koa-esm-transform","owner":"Polymer","description":"Middleware for Koa servers that transforms standard JavaScript modules to AMD modules for use with older browsers that don't support modules natively.","archived":false,"fork":false,"pushed_at":"2025-04-09T13:39:32.000Z","size":535,"stargazers_count":10,"open_issues_count":14,"forks_count":3,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-05-02T02:38:36.288Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Polymer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null}},"created_at":"2019-06-25T23:26:52.000Z","updated_at":"2024-05-16T22:13:06.000Z","dependencies_parsed_at":"2025-05-02T02:48:04.084Z","dependency_job_id":null,"html_url":"https://github.com/Polymer/koa-esm-transform","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Polymer/koa-esm-transform","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Polymer%2Fkoa-esm-transform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Polymer%2Fkoa-esm-transform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Polymer%2Fkoa-esm-transform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Polymer%2Fkoa-esm-transform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Polymer","download_url":"https://codeload.github.com/Polymer/koa-esm-transform/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Polymer%2Fkoa-esm-transform/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268479861,"owners_count":24256886,"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-02T02:00:12.353Z","response_time":74,"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":[],"created_at":"2024-11-12T14:16:45.143Z","updated_at":"2025-08-03T00:40:32.986Z","avatar_url":"https://github.com/Polymer.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koa-esm-transform\n\nMiddleware for Koa servers that transforms standard JavaScript modules to earlier versions of JavaScript and/or AMD modules (inlining loader script `@polymer/esm-amd-loader` into the HTML), for use with older browsers.  \n\nConsider an HTML file containing the following inline JavaScript module:\n\n```html\n\u003cscript type=\"module\"\u003e\nimport {someFunction} from './some-module.js';\nsomeFunction();\n\u003c/script\u003e\n```\n\nThe koa-esm-to-amd middleware would transform that HTML code to something like the following:\n\n```html\n\u003cscript\u003e\n// An inline loader script from `@polymer/esm-amd-loader` package\n// which adds the `define` function used below.\n\u003c/script\u003e\n\u003cscript\u003e\ndefine([\"./some-module.js\"], function (someModule) {\n  someModule.someFunction();\n});\n\u003c/script\u003e\n```\n\nBecause this is middleware, you can use it in a simple static file server as well with a proxy server.  This makes it possible to use in front of a test server such as the one `karma` starts up. (See [koa-karma-proxy](https://github.com/Polymer/koa-karma-proxy) for examples.)\n\nNote: HTML and JavaScript are parsed on every request for those content-types, it is intended for use in development context to facilitate build-free testing/iteration as opposed to in a high volume production web server.\n\n## How it works\n\nBy default, a set of babel transform plugins are chosen based on the known capabilities of the browser/user-agent identified in the Koa Context for the request.\n\nWhen the downstream server returns HTML content, it is scanned for module script tags (e.g. `\u003cscript type=\"module\"\u003e`).  Any `src` attribute values are appended with the `__esmTransform` query parameter.  The query parameter is added because the middleware needs to distinguish between scripts that are being imported as a module vs a traditional script and this can't necessarily be determined by looking at the script itself.\n\nInline module script content and URLs with the `__esmTransform` query parameter have their `import` specifiers appended with the `__esmTransform` to indicate the requested content should be treated as a module and compiled with the selected babel plugins.\n\nDepending on plugins being used, certain support scripts will also be inlined into the HTML, such as `@polymer/esm-amd-loader` and `regenerator-runtime`.\n\n## Options\n\n- `babelPlugins`: Either an Array of babel plugins (e.g. `[require('@babel/plugin-transform-modules-amd')]`) or a Function that takes a Koa Context and returns an Array of babel plugins `(ctx) =\u003e []`.  Providing a value for this option will override the default behavior of the middleware's capabilities-based babel plugin selection.\n- `exclude`: An array of requested paths or [minimatch](https://www.npmjs.com/package/minimatch) based patterns to match requested paths that should be excluded from any process/rewriting by the middleware.\n- `queryParam`: You can redefine the appended query parameter string from `__esmTransform` as something else.\n- `logger`: Middleware will call `debug`, `info`, `warn` and `error` methods on `console` to log events.  If you use a different logger for your application, provide it here.\n- `logLevel`: Set a minimum level for events to be logged to override the default level of `info`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolymer%2Fkoa-esm-transform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolymer%2Fkoa-esm-transform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolymer%2Fkoa-esm-transform/lists"}