vite-plugin-singlefile icon indicating copy to clipboard operation
vite-plugin-singlefile copied to clipboard

Support Web Worker files (eg. autocomplete.worker.js?worker syntax)

Open tysonstolarski opened this issue 1 year ago • 3 comments

It looks like web worker js files with the ?worker suffix are ignored by this plugin.

My app uses an import such as:

import AutocompleteWorker from "@/autocomplete.worker.js?worker";

My output produces:

npm run build

build vite build

vite v5.3.3 building for production... ✓ 293 modules transformed. rendering chunks (1)...

Inlining: index-CIvNPwLS.js Inlining: style-BvRGwxcl.css dist/autocomplete.worker-CFomeDza.js 90.96 kB dist/index.html 1,964.05 kB

I think it's just a matter of updating the isJsFile regex at https://github.com/richardtallent/vite-plugin-singlefile/blob/main/src/index.ts#L42 ?

tysonstolarski avatar Jul 24 '24 01:07 tysonstolarski

Same issues with Service Worker... not able to ignore such patters, even despite of !service.mjs or !(service).mjs.

L2NE-dev avatar Jul 24 '24 16:07 L2NE-dev

using let worker_import = await import("@x.worker.js?worker&inline"); worked for me

nikoPLP avatar Jul 28 '24 02:07 nikoPLP

@nikoPLP yes, but that's making a packaging decision at all the call sites for web/service workers. Ideally the application code stays agnostic to how the final scripts are bundled up, and it's just the configuration of this singlefile plugin that controls inlining vs normal vite packaging.

tysonstolarski avatar Aug 12 '24 07:08 tysonstolarski