{"_id":"@aidenlx/esbuild-plugin-inline-worker","_rev":"1-98545b1e19943bb8e939d476a044cd0c","name":"@aidenlx/esbuild-plugin-inline-worker","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@aidenlx/esbuild-plugin-inline-worker","description":"Esbuild loader for inline Web Workers","version":"1.0.0","keywords":["workers","esbuild"],"license":"MIT","type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"import":"./dist/plugin.js","types":"./dist/plugin.d.ts"},"./utils":{"import":"./dist/utils.js","types":"./dist/utils.d.ts"}},"scripts":{"build":"rimraf dist && tsc"},"peerDependencies":{"esbuild":"^0.17.4"},"dependencies":{"nanoid":"~4.0.0"},"devDependencies":{"typescript":"^4.9.4","@types/node":"^17.0.10","rimraf":"^3.0.2"},"gitHead":"5fca1ea1cfe4ecceca662abd7bb0f73d6ce5e70c","_id":"@aidenlx/esbuild-plugin-inline-worker@1.0.0","_nodeVersion":"18.12.1","_npmVersion":"8.19.2","dist":{"integrity":"sha512-sKxAWBQSgkgO+S2nHsZzJMzSmdz1ORJ+0q3nv4X19p4X6dl7YM2MAbn4RV/Kzzniyl2ptsf4R5fBHOB05yROqg==","shasum":"6ebe736ef27e6c7d8e60d6917b73dff1946b5696","tarball":"https://registry.npmjs.org/@aidenlx/esbuild-plugin-inline-worker/-/esbuild-plugin-inline-worker-1.0.0.tgz","fileCount":15,"unpackedSize":23276,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGuV731OKBU+H2J2lJnxOghN/IYiHsLO7svzElD8N8sBAiBDK80vXe2MFvMJdPLL53VnAh6bzeG3ZlfwPL3mpn9O+g=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkCpiUACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqXbg/+KPdfXy9GM9SxAjLMRCbYShWV27Abc1ywGD76pFViUVbAZQ92\r\ni1G+8kURMXsFgxo7czglfnrC40+d0uU2TTVf+kqK4kis6Fg+nWVksKGSao6M\r\njX0XNvIIPkt0JyOcbUXmd1WqZAZOCpWkw94aREbuP92GtrnDt/0+wUNZwFqk\r\n/RYLiaHwxW4EDILvhO1FyUzhw+ZFfPIuXFLNMLFyzvU0Q7gsY+Ec5sCo24Mn\r\nxyHJT8GdLoxR1A2DV5zE9pvOEUhZWDRlkX27MyPfiswd17vCu46P8Nqn6qst\r\n9QtZtJuKkp3bADdMWFPzMr4BpeVz2sWCJETUIbv/zzxk8CCrrBEFhPdzhbn9\r\nG/33T9+5yBmQzLlaUAXk4/pu7FST0xNZVnfbhI7vDgT7nnM6TJgWOcIgCBLh\r\n9u61d2BMSjmeoSZucxjuNQgoGJYyi3RXdTiLtDpPAuQguhmI2+F4mndeEa0t\r\nr2bIT2sC2xNUKucYQCPbmLSCo25EWTS0ZgdhJvYEhUY+7TosjCDkfxNXs9vj\r\nyIQkjgV6cu7nz7MYt4nIiFw1SgvRlBPcoDH313705BX+xWZsApGulnREcyDi\r\nGRXFCK+UyKXWUHFlW9ZPduiEXYNGr8RqdkTOwrmaU/9xZjmRrCc6CBwkR6bj\r\n6dlv0pY4ytl6q4nKdIBaostYIVTTyEa4GVM=\r\n=hIO2\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"aidenlx","email":"aiden.lx@outlook.com"},"directories":{},"maintainers":[{"name":"aidenlx","email":"aiden.lx@outlook.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/esbuild-plugin-inline-worker_1.0.0_1678416020425_0.6381108660991739"},"_hasShrinkwrap":false},"1.0.1":{"name":"@aidenlx/esbuild-plugin-inline-worker","description":"Esbuild inline web workers loader","version":"1.0.1","keywords":["workers","esbuild"],"license":"MIT","type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"import":"./dist/plugin.js","types":"./dist/plugin.d.ts"},"./utils":{"import":"./dist/utils.js","types":"./dist/utils.d.ts"}},"scripts":{"build":"rimraf dist && tsc"},"peerDependencies":{"esbuild":"^0.17.4"},"dependencies":{"nanoid":"~4.0.0"},"devDependencies":{"typescript":"^4.9.4","@types/node":"^17.0.10","rimraf":"^3.0.2"},"gitHead":"80e9579d3a69710f8b160abba81bf2baba31a1e7","_id":"@aidenlx/esbuild-plugin-inline-worker@1.0.1","_nodeVersion":"18.12.1","_npmVersion":"8.19.2","dist":{"integrity":"sha512-of5EuzeFgVoBU4qHCFjxgk3UsHafev9pUMJXZ5DpWRJ6i3pCh7N+B1HHHrphDnT4J4u1XPtRaeMJ8KvvsNwcbQ==","shasum":"8e98297aa5a8f3bcd82d169fd06fbd152eee3b51","tarball":"https://registry.npmjs.org/@aidenlx/esbuild-plugin-inline-worker/-/esbuild-plugin-inline-worker-1.0.1.tgz","fileCount":8,"unpackedSize":12067,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDHST37tHTZTj8uhQAVu2MeBXDhFhHlVXGhAZYZ2zht7AIgXSgSGOMB4Eymmwwggc1rDnaZ9VB/YL+A4u4B7SFFBK8="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkCppfACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqfyw/5ANfGk94s6cD59b/2PlUMxbKpNSrggE0GI4CXcy8Z0KGR9bWs\r\na65ezxL/iu5KqaE5ksLBZ/ufGMp12sDdoE+0ZJAg3cbavVm2tBc4wCBx22av\r\n3GISXsazEwvibA+FwO3IaX9oqmCgMpf3x10EDzeni4ScMIxdis9ofYTsiLVw\r\neP1K5YCQ5BBcV5/wui1deGzb3Ax2C7g9fSR4fKCTnlbETyetUL196X76l32a\r\n7gaDIRf8sV6Iufat9ROp/vu7ssNdNKCBTSmPjMIMO6gjhWEUda1PndOrtGY3\r\nXzaajzaM1f3QeyDg4oN3wV7pEylYwLBAV/fKNWWQH4MRbhYF9VQmT22Coqle\r\nd7QYSGbBNIP4hsuKKn6iSxzYnHL72Bejq9teoDQVgaZCgFo/GXzoEvYE+x0a\r\n0jnpjDubIS+f29fyKMBWRbxGAM/ZqaCF+RnCnr9O3V5eL5J+kc0J9ZNDYjBX\r\nV3QZqBz3XGVMNOvtp8jde/nR2qzIS6UB1FxN/ya4dgkBZxKw0ciwonTsVMvz\r\nhhKbNAPCtcR14sqpq5EmWhZulQVO6kjm0EnRfAJ93JqMMgweWJsEBhy1yrBZ\r\nMU2RVr8buJ5C53T8uX7jlSO571r5P6b+UabyFhrGrDbXIgRgofkBVXYP8R+B\r\nPIZ8wBON5xrCgqmmT9Skt1JjUu74icvpj60=\r\n=5yiM\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"aidenlx","email":"aiden.lx@outlook.com"},"directories":{},"maintainers":[{"name":"aidenlx","email":"aiden.lx@outlook.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/esbuild-plugin-inline-worker_1.0.1_1678416479177_0.02619441787603427"},"_hasShrinkwrap":false}},"time":{"created":"2023-03-10T02:40:20.345Z","1.0.0":"2023-03-10T02:40:20.588Z","modified":"2023-03-10T02:47:59.446Z","1.0.1":"2023-03-10T02:47:59.362Z"},"maintainers":[{"name":"aidenlx","email":"aiden.lx@outlook.com"}],"description":"Esbuild inline web workers loader","keywords":["workers","esbuild"],"license":"MIT","readme":"# Inline Worker Plugin for esbuild 0.17+\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 @aidenlx/esbuild-plugin-inline-worker\n-- or --\nyarn add -D @aidenlx/esbuild-plugin-inline-worker\n-- or --\npnpm add -D @aidenlx/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 \"@aidenlx/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 \"@aidenlx/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 \"@aidenlx/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) => 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) => {\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","readmeFilename":"README.md"}