{"id":27954341,"url":"https://github.com/polyipseity/esbuild-plugin-inline-worker","last_synced_at":"2026-02-14T16:33:37.401Z","repository":{"id":283110115,"uuid":"950704210","full_name":"polyipseity/esbuild-plugin-inline-worker","owner":"polyipseity","description":"Esbuild inline web workers loader","archived":false,"fork":false,"pushed_at":"2025-03-18T16:14:32.000Z","size":38703,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-25T19:46:15.673Z","etag":null,"topics":["esbuild","workers"],"latest_commit_sha":null,"homepage":"","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/polyipseity.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}},"created_at":"2025-03-18T15:05:18.000Z","updated_at":"2025-03-18T15:43:19.000Z","dependencies_parsed_at":"2025-03-18T16:40:51.824Z","dependency_job_id":"15848357-b275-48f3-879a-7996d16bf2ed","html_url":"https://github.com/polyipseity/esbuild-plugin-inline-worker","commit_stats":null,"previous_names":["polyipseity/esbuild-plugin-inline-worker"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/polyipseity/esbuild-plugin-inline-worker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyipseity%2Fesbuild-plugin-inline-worker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyipseity%2Fesbuild-plugin-inline-worker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyipseity%2Fesbuild-plugin-inline-worker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyipseity%2Fesbuild-plugin-inline-worker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polyipseity","download_url":"https://codeload.github.com/polyipseity/esbuild-plugin-inline-worker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyipseity%2Fesbuild-plugin-inline-worker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29449372,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-14T15:52:44.973Z","status":"ssl_error","status_checked_at":"2026-02-14T15:52:11.208Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["esbuild","workers"],"created_at":"2025-05-07T17:25:24.750Z","updated_at":"2026-02-14T16:33:37.397Z","avatar_url":"https://github.com/polyipseity.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Inline Worker Plugin for esbuild 0.17+\n\n_forked from [PKM-er/obsidian-zotlit](https://github.com/PKM-er/obsidian-zotlit/tree/160842953d29520ad8507f99ba5e1dd51ae75885/utils/esbuild-inline-worker)_\n\nThis is a plugin for [esbuild](https://esbuild.github.io) which allows you to import module as bundled script text for usage in Web Workers. Support watch mode, and custom worker import pattern and build options.\n\nSpecial thanks to [esbuild-plugin-inline-import](https://github.com/mitschabaude/esbuild-plugin-inline-worker) for the idea.\n\n## Installation\n\n```sh\nnpm install -D @polyipseity/esbuild-plugin-inline-worker\n-- or --\nyarn add -D @polyipseity/esbuild-plugin-inline-worker\n-- or --\npnpm add -D @polyipseity/esbuild-plugin-inline-worker\n```\n\n## Usage\n\nBy default the plugin intercepts all `worker:*` imports and replaces them with the bundled script text. For example:\n\n```js\nimport WorkerCode from \"worker:./worker.js\";\n// you can use utils to create a worker from the script text\nimport { fromScriptText } from \"@polyipseity/esbuild-plugin-inline-worker/utils\";\n\nconst worker = fromScriptText(\n  WorkerCode,\n  /** worker options */ { name: \"i'm a worker\" }\n);\n```\n\nTo enable the plugin, add it to the `plugins` option of esbuild:\n\n```js\nimport { build } from \"esbuild\";\nimport inlineWorker from \"@polyipseity/esbuild-plugin-inline-worker\";\n\nawait build({\n  // ...other options\n  plugins: [inlineWorker()],\n});\n```\n\nIf you are using TypeScript, you can create a file named `inline-worker.d.ts` in your source code folder with the following content :\n\n```ts\ndeclare module \"worker:*\" {\n  const inlineWorker: string;\n  export default inlineWorker;\n}\n```\n\n### Watch mode support\n\nIf you are using esbuild v0.17+ in watch mode, you can use the `watch` option to enable watch mode support:\n\n```js\nimport { build } from \"esbuild\";\nimport inlineWorker from \"@polyipseity/esbuild-plugin-inline-worker\";\n\n// you can replace this with your own build mode detection logic\nconst isProd = process.env.NODE_ENV === \"production\";\n\n/** @type import(\"esbuild\").BuildOptions */\nconst commonOptions = {\n  // ...\n};\n\n/** @type import(\"esbuild\").BuildOptions */\nconst mainOptions = {\n  ...commonOptions,\n  plugins: [inlineWorker({ watch: !isProd })],\n};\n\nif (!isProd) {\n  // watch mode\n  const ctx = await context(mainOptions);\n  try {\n    await ctx.watch();\n  } catch (err) {\n    console.error(err);\n    await cleanup();\n  }\n  process.on(\"SIGINT\", cleanup);\n  // clean up properly before exit via ctrl+c\n  async function cleanup() {\n    await ctx.dispose();\n  }\n} else {\n  // build mode\n  await build(mainOptions);\n}\n```\n\n### Custom Worker Import Pattern\n\nYou can use the `filter` option to customize the import pattern. For example, the default pattern `worker:*` works like this:\n\n```js\nawait build({\n  // ...other options\n  plugins: [\n    inlineWorkerPlugin({\n      filter: {\n        pattern: /^worker:/,\n        // if you don't need to transform the path, you can just ignore this option\n        transform: (path, pattern) =\u003e path.replace(pattern, \"\"),\n      },\n    }),\n  ],\n});\n```\n\nTo only intercept `*.worker.js` imports, you can use:\n\n```js\nawait build({\n  // ...other options\n  plugins: [inlineWorkerPlugin({ filter: { pattern: /\\.worker\\.js$/ } })],\n});\n```\n\nRemember to change the `inline-worker.d.ts` file to match the new pattern:\n\n```ts\ndeclare module \"*.worker.js\" {\n  const inlineWorker: string;\n  export default inlineWorker;\n}\n```\n\n### Custom Build Options\n\nYou can pass a function to the `buildOptions` option to customize the build options for each worker file:\n\n```js\nawait build({\n  // ...other options\n  plugins: [\n    inlineWorkerPlugin({\n      // `entryPoint` point to the full path to the worker file\n      // `path` is the path used in `import` statement,\n      // and it's relative to `resolveDir`\n      // `resolve` method is used by esbuild to resolve the import paths\n      buildOptions: ({ path, resolveDir, entryPoint }, resolve) =\u003e {\n        let tsconfig = \"tsconfig.worker.json\";\n        if (path.endsWith(\"worker-special.js\")) {\n          // use a different tsconfig file for different worker files\n          tsconfig = \"tsconfig.worker-special.json\";\n        } else if (path.startsWith(\"@/worker/\")) {\n          // get the tsconfig file next to the worker file\n          tsconfig = join(entryPoint, \"..\", \"tsconfig.json\");\n        }\n        return {\n          sourcemap: !isProd ? \"inline\" : undefined,\n          tsconfig,\n        };\n      },\n    }),\n  ],\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolyipseity%2Fesbuild-plugin-inline-worker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolyipseity%2Fesbuild-plugin-inline-worker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolyipseity%2Fesbuild-plugin-inline-worker/lists"}