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
12 changes: 4 additions & 8 deletions packages/vips/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import Vips from 'wasm-vips';
// @ts-expect-error - WASM files are inlined as base64 data URLs at build time
import VipsModule from 'wasm-vips/vips.wasm';

// @ts-expect-error - WASM files are inlined as base64 data URLs at build time
import VipsJxlModule from 'wasm-vips/vips-jxl.wasm';

// @ts-expect-error - WASM files are inlined as base64 data URLs at build time
import VipsHeifModule from 'wasm-vips/vips-heif.wasm';

Expand Down Expand Up @@ -44,17 +41,16 @@ async function getVips(): Promise< typeof Vips > {
}

vipsInstance = await Vips( {
// Load JXL and HEIF dynamic modules for full format support.
// wasm-vips defaults to ["vips-jxl.wasm", "vips-heif.wasm"].
dynamicLibraries: [ 'vips-jxl.wasm', 'vips-heif.wasm' ],
// Load HEIF dynamic module for HEIF/HEIC and AVIF format support.
// JXL is omitted as WordPress Core does not currently support it.
// It can be re-added when Core adds JXL support.
dynamicLibraries: [ 'vips-heif.wasm' ],
locateFile: ( fileName: string ) => {
// WASM files are inlined as base64 data URLs at build time,
// eliminating the need for separate file downloads and avoiding
// issues with hosts not serving WASM files with correct MIME types.
if ( fileName.endsWith( 'vips.wasm' ) ) {
return VipsModule;
} else if ( fileName.endsWith( 'vips-jxl.wasm' ) ) {
return VipsJxlModule;
} else if ( fileName.endsWith( 'vips-heif.wasm' ) ) {
return VipsHeifModule;
}
Expand Down
12 changes: 2 additions & 10 deletions test/e2e/specs/editor/various/wasm-inlining.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,10 @@ test.describe( 'WASM Inlining (build verification)', () => {
);
} );

test( 'should inline vips-jxl.wasm as base64 data URL', () => {
// Verify vips-jxl.wasm is inlined
// Variable name: vips_jxl_default (from wasm-vips/vips-jxl.wasm)
expect( buildContent ).toMatch(
/var vips_jxl_default\s*=\s*"data:application\/wasm;base64,/
);
} );

test( 'should have substantial inlined WASM data', () => {
// The inlined WASM should be large (original files are several MB)
// This ensures we're actually inlining the full WASM, not just a stub
// The built file should be at least 10MB due to the inlined WASM
expect( buildContent.length ).toBeGreaterThan( 10 * 1024 * 1024 );
// The built file should be at least 5MB due to the inlined WASM
expect( buildContent.length ).toBeGreaterThan( 5 * 1024 * 1024 );
} );
} );
Loading