{"id":13725517,"url":"https://github.com/surma/rollup-plugin-off-main-thread","last_synced_at":"2025-05-14T23:07:50.690Z","repository":{"id":35022752,"uuid":"197596883","full_name":"surma/rollup-plugin-off-main-thread","owner":"surma","description":"Use Rollup with workers and ES6 modules today.","archived":false,"fork":false,"pushed_at":"2024-09-27T06:02:31.000Z","size":245,"stargazers_count":312,"open_issues_count":18,"forks_count":32,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-11T10:13:20.825Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/surma.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-18T13:54:24.000Z","updated_at":"2025-03-17T09:25:24.000Z","dependencies_parsed_at":"2022-07-16T01:00:29.358Z","dependency_job_id":"5cfd0da7-0dc4-48a2-97a6-bfcb1baa4e14","html_url":"https://github.com/surma/rollup-plugin-off-main-thread","commit_stats":{"total_commits":198,"total_committers":17,"mean_commits":"11.647058823529411","dds":0.6161616161616161,"last_synced_commit":"27e2a18c788b2153fa241b1bd29f24f4a2c4ecbc"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surma%2Frollup-plugin-off-main-thread","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surma%2Frollup-plugin-off-main-thread/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surma%2Frollup-plugin-off-main-thread/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surma%2Frollup-plugin-off-main-thread/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/surma","download_url":"https://codeload.github.com/surma/rollup-plugin-off-main-thread/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254243362,"owners_count":22038046,"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","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-08-03T01:02:25.769Z","updated_at":"2025-05-14T23:07:45.681Z","avatar_url":"https://github.com/surma.png","language":"JavaScript","funding_links":[],"categories":["Plugins","JavaScript"],"sub_categories":["Workflow"],"readme":"# rollup-plugin-off-main-thread\n\nUse Rollup with workers and ES6 modules _today_.\n\n```\n$ npm install --save @surma/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 \"@surma/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 `\u003cscript\u003e` 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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurma%2Frollup-plugin-off-main-thread","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsurma%2Frollup-plugin-off-main-thread","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurma%2Frollup-plugin-off-main-thread/lists"}