Skip to content

Commit 15e9c38

Browse files
committed
docs: add bundler setup section
1 parent 6916063 commit 15e9c38

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ The encoder automatically tries these locations:
8484
3. Package worker file (fallback, may require CORS setup)
8585
4. Inline helper (shows setup instructions if above fail)
8686

87+
## Setup for Vite/PWA projects
88+
89+
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`:
90+
91+
```ts
92+
const workerUrl = new URL(
93+
'./node_modules/webcodecs-encoder/dist/worker.js',
94+
import.meta.url
95+
).toString();
96+
97+
await encoder.initialize({ workerScriptUrl: workerUrl });
98+
```
99+
100+
This allows your bundler to include the worker script in the build and serve it correctly without any manual steps.
101+
87102
## Basic Usage
88103

89104
### Traditional API (Constructor-based)

0 commit comments

Comments
 (0)