Skip to content

Update @wordpress/vips package with fully inlined wasm-vips build #74352

@adamsilverstein

Description

@adamsilverstein

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

  1. 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.
  1. 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.
  1. 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.
  1. Memory Lifecycle Management:
  • Implement a terminate() method that revokes the Object URL and terminates the Worker to reclaim used memory.

Acceptance Criteria:

  • Package builds a single entry point; no .wasm or .worker.js files are emitted to the build/ folder.
  • Network tab shows zero requests for vips.wasm or worker.js when the library loads.
  • Vips initializes correctly using the Blob worker URL.
  • Automated tests verify that inlined loading set up as expected and URL.revokeObjectURL is called upon cleanup.

Metadata

Metadata

No fields configured for Enhancement.

Projects

Status
✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions