Overview
Set up a new private package that wraps wasm-vips. To ensure the library works in any WordPress environment (including those with restrictive CSPs or CDN issues), adopt a "Single-File" strategy. Both the .wasm binary and the worker.js glue code must be embedded directly into the main JavaScript bundle.
See swissspidy/media-experiments#753 for how this was implemented in the Media Experiments plugin.
What is your proposed solution?
See sub issues for details
- Configure Build Pipeline (Webpack/Rollup):
- Create a build script that reads vips.wasm and converts it to a Base64 string at build time.
- Inject this string into a constant (e.g., WASM_BINARY_BASE64) in the generated JavaScript.
- Implement Blob-Based Worker Loader:
- Load vips.worker.js from a URL code as a string.
- Create a Blob from this string and generate a local Object URL (URL.createObjectURL(blob)).
- Initialize the Worker using this local Object URL.
- Implement Custom Vips Instantiation:
- Override the default wasm-vips fetch behavior.
- Decode the WASM_BINARY_BASE64 string to a Uint8Array.
- Pass this buffer directly to the Vips module constructor (via the wasmBinary or locateFile override) to bypass the network request entirely.
- Memory Lifecycle Management:
- Implement a terminate() method that revokes the Object URL and terminates the Worker to reclaim used memory.
Acceptance Criteria:
Overview
Set up a new private package that wraps
wasm-vips. To ensure the library works in any WordPress environment (including those with restrictive CSPs or CDN issues), adopt a "Single-File" strategy. Both the .wasm binary and the worker.js glue code must be embedded directly into the main JavaScript bundle.See swissspidy/media-experiments#753 for how this was implemented in the Media Experiments plugin.
What is your proposed solution?
See sub issues for details
Acceptance Criteria: