{"id":13448645,"url":"https://github.com/mizchi/trans-loader","last_synced_at":"2026-03-05T13:02:47.262Z","repository":{"id":137924109,"uuid":"139000141","full_name":"mizchi/trans-loader","owner":"mizchi","description":"webpack-less frontend with service-worker","archived":false,"fork":false,"pushed_at":"2018-09-02T08:22:33.000Z","size":4456,"stargazers_count":99,"open_issues_count":3,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-28T08:44:50.933Z","etag":null,"topics":["babel","jspm","service-worker","trans-loader","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"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/mizchi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2018-06-28T09:56:59.000Z","updated_at":"2024-04-25T10:34:03.000Z","dependencies_parsed_at":"2024-01-27T11:56:47.006Z","dependency_job_id":null,"html_url":"https://github.com/mizchi/trans-loader","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mizchi/trans-loader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizchi%2Ftrans-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizchi%2Ftrans-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizchi%2Ftrans-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizchi%2Ftrans-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mizchi","download_url":"https://codeload.github.com/mizchi/trans-loader/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizchi%2Ftrans-loader/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30127218,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T12:40:50.676Z","status":"ssl_error","status_checked_at":"2026-03-05T12:39:32.209Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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","jspm","service-worker","trans-loader","typescript"],"created_at":"2024-07-31T05:01:51.530Z","updated_at":"2026-03-05T13:02:47.239Z","avatar_url":"https://github.com/mizchi.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# trans-loader\n\nYou don't need **npm** and **bundler**.\n\nYou need just a `service-worker` script.\n\n## What this script does...\n\n- Transform `.js` with babel on service-worker\n- Transform `.ts` and `.tsx` with typescript on service-worker\n- Load modules from [jspm.io](https://jspm.io) and cache them on serviceWorker.\n\n## CAUTION!\n\n- **development only**. Do not use for production.\n- It works only for modern browser(ES2015+ and ES Modules ready).\n\n## How to use\n\nPut [dist/sw.js](/dist/sw.js) as `/sw.js` on your app root.\n\n```sh\nwget https://raw.githubusercontent.com/mizchi/trans-loader/master/dist/sw.js\n```\n\nRewrite your entry js like below.\n\nBefore\n\n```html\n\u003cscript src=\"/src/main.js\"\u003e\u003c/script\u003e\n```\n\nAfter\n\n```html\n\u003cscript type=module\u003e\n(async () =\u003e {\n  const run = () =\u003e import('/src/main.js') // your entry js\n  if (navigator.serviceWorker.controller) {\n    run()\n  } else {\n    const reg = await navigator.serviceWorker.register(\"/sw.js\");\n    await navigator.serviceWorker.ready;\n    navigator.serviceWorker.addEventListener('controllerchange', run)\n  }\n})()\n\u003c/script\u003e\n```\n\nSee [working demo](/demo)\n\n## Example 1: Compiled with babel\n\n```js\n// /your-entry.js\nimport React from \"react\";\nimport ReactDOM from \"react-dom\";\nReactDOM.render(\u003ch1\u003eHello\u003c/h1\u003e, document.querySelector(\".root\"));\n```\n\n## Example 2: Load relative file\n\n```\nindex.html\nsw.js\nsrc/main.js\nsrc/components/App.js\n```\n\n```js\n// main.js\nimport React from \"react\";\nimport ReactDOM from \"react-dom\";\nimport App from \"./components/App\";\nReactDOM.render(\u003cApp /\u003e, document.querySelector(\".root\"));\n```\n\n## Example 3: Load typescript\n\n```\nindex.html\nsw.js\nsrc/main.js\nsrc/components/App.tsx\n```\n\n```js\n// main.js\nimport React from \"react\";\nimport ReactDOM from \"react-dom\";\nimport App from \"./components/App\";\nReactDOM.render(\u003cApp /\u003e, document.querySelector(\".root\"));\n```\n\n## Example 4: Loading with `package.json`'s version\n\n```\nindex.html\nsw.js\npackage.json\nsrc/main.js\n```\n\n`package.json`\n\n```\n{\n  \"dependencies\": {\n    \"react\": \"16.4.1\",\n    \"react-dom\": \"16.4.1\"\n  }\n}\n```\n\nLog\n\n```\ntrans-loader: Cache https://dev.jspm.io/react@16.4.1\ntrans-loader: Cache https://dev.jspm.io/react-dom@16.4.1\n```\n\n## How it works\n\n### Rewrite js content with service-worker proxy\n\nCompile content with babel/typescript by extname\n\n```js\n// ...\nself.addEventListener(\"fetch\", (event: any) =\u003e {\n  if (event.request.url.indexOf(\"dev.jspm.io\") \u003e -1) {\n    // cache jspm result\n    event.respondWith(useCacheOrLoad(event.request));\n  } else if (event.request.url.indexOf(\"/src/\") \u003e -1) {\n    // transform\n    console.log(\"trans-loader: with-transform\", event.request.url);\n    event.respondWith(respondWithTransform(event.request.url));\n  }\n});\n```\n\n\n### Rewrite to dev.jspm.io\n\nRewrite npm module path to `dev.jspm.io`. See [this code](/src/rewriteModulePath.js)\n\n```js\n// before\nimport React from \"react\";\n// after\nimport React from \"https://dev.jspm.io/react\";\n```\n\n### Add valid extname\n\n- Try to access `.js, .mjs, .ts, .tsx, /index.js, /index.ts, /index.tsx`\n- return file with non-error endpoint\n\n## LICENSE\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmizchi%2Ftrans-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmizchi%2Ftrans-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmizchi%2Ftrans-loader/lists"}