{"_id":"@trickfilm400/rollup-plugin-off-main-thread@4.0.0","bugs":{"url":"https://github.com/Trickfilm400/rollup-plugin-off-main-thread/issues"},"dist":{"shasum":"cfa69cc048ffdc8e1943ee31b8bb7e5a56a4e7b5","tarball":"http://registry-npm.ywwl.com/@trickfilm400/rollup-plugin-off-main-thread/download/@trickfilm400/rollup-plugin-off-main-thread-4.0.0.tgz","integrity":"sha512-rQSqTcqD5c1H1qAR2XO1wHYGtd3NbMdU7oMD0gDW7xkxEIQ/fDe0MCMJtdDqVSrmmznxL2xfcxnGnusXX9JKBQ==","fileCount":6,"unpackedSize":29685,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@trickfilm400%2frollup-plugin-off-main-thread@4.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDWQ1kRDD2AenLESzID+jRQ9nGqbqm0BqrsLNHeiHGGQQIhAIVLoIXBDObZwa8f83jtB65EIpsKE11eC8OPbj171oMx"}],"size":10104,"noattachment":false,"key":"/@trickfilm400/rollup-plugin-off-main-thread/-/@trickfilm400/rollup-plugin-off-main-thread-4.0.0.tgz"},"main":"index.js","name":"@trickfilm400/rollup-plugin-off-main-thread","author":{"name":"Surma","email":"surma@google.com"},"engines":{"node":">=12"},"gitHead":"710d9cb0cf858fd943954616b8563509767c1cc7","license":"Apache-2.0","scripts":{"fmt":"prettier --write 'tests/**/*.js' *.js *.md *.json","test":"node ./run_tests.js"},"version":"4.0.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"81571caa-63ca-4d62-a709-2341bcf8d6fa"},"approver":{"name":"trickfilm400","email":"trickfilm400@gmail.com"}},"homepage":"https://github.com/Trickfilm400/rollup-plugin-off-main-thread#readme","repository":{"url":"git+https://github.com/Trickfilm400/rollup-plugin-off-main-thread.git","type":"git"},"_npmVersion":"12.2.0","description":"Use Rollup with workers and ES6 modules today.","directories":{},"maintainers":[{"name":"trickfilm400","email":"trickfilm400@gmail.com"}],"_nodeVersion":"24.21.0","contributors":[{"name":"trickfilm400","email":"trickfilm400@gmail.com"}],"dependencies":{"ejs":"^7.0.1","json5":"^2.2.3","magic-string":"^0.30.21"},"devDependencies":{"chai":"4.5.0","chalk":"^4.1.2","karma":"^6.4.4","mocha":"^12.0.3","rollup":"^4.64.0","prettier":"^3.9.9","karma-chai":"0.1.0","karma-mocha":"^2.0.1","karma-chrome-launcher":"3.2.0","karma-safari-launcher":"1.0.0","karma-firefox-launcher":"^2.1.3","karma-safaritechpreview-launcher":"2.0.2"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/rollup-plugin-off-main-thread_4.0.0_1791318705856_0.5940019054013337"},"_hasShrinkwrap":false,"readme":"# rollup-plugin-off-main-thread\n\nUse Rollup with workers and ES6 modules _today_.\n\n```\n$ npm install --save @trickfilm400/rollup-plugin-off-main-thread\n```\n\nWorkers are JavaScript’s version of threads. [Workers are important to use][when workers] as the main thread is already overloaded, especially on slower or older devices.\n\nThis plugin takes care of shimming module support in workers and allows you to use `new Worker()`.\n\nOMT is the result of merging loadz0r and workz0r.\n\n## Usage\n\nI set up [a gist] to show a full setup with OMT.\n\n### Config\n\n```js\n// rollup.config.js\nimport OMT from \"@trickfilm400/rollup-plugin-off-main-thread\";\n\nexport default {\n  input: [\"src/main.js\"],\n  output: {\n    dir: \"dist\",\n    // You _must_ use either “amd” or “esm” as your format.\n    // But note that only very few browsers have native support for\n    // modules in workers.\n    format: \"amd\"\n  },\n  plugins: [OMT()]\n};\n```\n\n### Auto bundling\n\nIn your project's code use a module-relative path via `new URL` to include a Worker:\n\n```js\nconst worker = new Worker(new URL(\"worker.js\", import.meta.url), {\n  type: \"module\"\n});\n```\n\nThis will just work.\n\nIf required, the plugin also supports plain literal paths:\n\n```js\nconst worker = new Worker(\"./worker.js\", { type: \"module\" });\n```\n\nHowever, those are less portable: in Rollup they would result in module-relative\npath, but if used directly in the browser, they'll be relative to the document\nURL instead.\n\nHence, they're deprecated and `new URL` pattern is encouraged instead for portability.\n\n### Importing workers as URLs\n\nIf your worker constructor doesn't match `workerRegexp` (see options below), you might find it easier to import the worker as a URL. In your project's code:\n\n```js\nimport workerURL from \"omt:./worker.js\";\nimport paintWorkletURL from \"omt:./paint-worklet.js\";\n\nconst worker = new Worker(workerURL, { name: \"main-worker\" });\nCSS.paintWorklet.addModule(paintWorkletURL);\n```\n\n`./worker.js` and `./paint-worklet.js` will be added to the output as chunks.\n\n## Options\n\n```js\n{\n  // ...\n  plugins: [OMT(options)];\n}\n```\n\n- `loader`: A string containing the EJS template for the amd loader. If `undefined`, OMT will use `loader.ejs`.\n- `useEval`: Use `fetch()` + `eval()` to load dependencies instead of `<script>` tags and `importScripts()`. _This is not CSP compliant, but is required if you want to use dynamic imports in ServiceWorker_.\n- `workerRegexp`: A RegExp to find `new Workers()` calls. The second capture group _must_ capture the provided file name without the quotes.\n- `amdFunctionName`: Function name to use instead of AMD’s `define`.\n- `prependLoader`: A function that determines whether the loader code should be prepended to a certain chunk. Should return true if the load is suppsoed to be prepended.\n- `urlLoaderScheme`: Scheme to use when importing workers as URLs. If `undefined`, OMT will use `\"omt\"`.\n\n[when workers]: https://dassur.ma/things/when-workers\n[a gist]: https://gist.github.com/surma/a02db7b53eb3e7870bf539b906ff6ff6\n\n---\n\nLicense Apache-2.0\n","publish_time":1791318705957,"_cnpm_publish_time":1791318705957,"dist-tags":{"beta":"4.0.0-pre3","latest":"4.0.0"}}