From 15e9c389817b4f11842ffc72248ea51dcbb1b293 Mon Sep 17 00:00:00 2001 From: Romot Date: Wed, 28 May 2025 02:58:02 +0900 Subject: [PATCH] docs: add bundler setup section --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 88ca5a2..2a51283 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,21 @@ The encoder automatically tries these locations: 3. Package worker file (fallback, may require CORS setup) 4. Inline helper (shows setup instructions if above fail) +## Setup for Vite/PWA projects + +If you're bundling your application with tools like **Vite**, **Webpack**, or **Rollup**, you can let the bundler resolve the worker file directly instead of copying it manually. Construct the worker URL using `import.meta.url`: + +```ts +const workerUrl = new URL( + './node_modules/webcodecs-encoder/dist/worker.js', + import.meta.url +).toString(); + +await encoder.initialize({ workerScriptUrl: workerUrl }); +``` + +This allows your bundler to include the worker script in the build and serve it correctly without any manual steps. + ## Basic Usage ### Traditional API (Constructor-based)