Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ yarn add webcodecs-encoder

Running `npm install` will automatically run the `postinstall` script, applying a patch to `@types/dom-webcodecs` via `patch-package`. This patch restores the `AudioSampleFormat` type that is commented out in the published definitions.

The same `postinstall` script also tries to copy the Web Worker and AudioWorklet files into a `public/` directory. If your environment disables lifecycle scripts (for example using `--ignore-scripts` or Yarn Plug'n'Play), this step won't run. In that case you can copy `node_modules/webcodecs-encoder/dist/worker.js` and `node_modules/webcodecs-encoder/dist/audio-worklet-processor.js` to your public folder manually or run `node scripts/postinstall.js` yourself. Set the environment variable `WEB_CODECS_ENCODER_SKIP_COPY=1` before installing to disable the automatic copy.

## ✨ Zero-Config Setup (Automatic)

The package automatically attempts to copy the worker file to your `public/` directory during installation. In most cases, no additional setup is required!
Expand All @@ -64,6 +66,10 @@ If automatic setup didn't work or you need custom configuration:
cp node_modules/webcodecs-encoder/dist/worker.js public/webcodecs-worker.js
```

### Disable Automatic Worker Copy

Set `WEB_CODECS_ENCODER_SKIP_COPY=1` before installation if you want to skip the copy performed by the `postinstall` script.

### Or Specify Custom Worker URL

```typescript
Expand Down
4 changes: 4 additions & 0 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ function safeCopy(source, destination) {

// Main installation logic
function installWorker() {
if (process.env.WEB_CODECS_ENCODER_SKIP_COPY) {
console.log('WEB_CODECS_ENCODER_SKIP_COPY is set, skipping worker copy.');
return;
}
// Check if we're being run from within node_modules via package path
const cwd = process.cwd();
const packagePath = packageRoot;
Expand Down