Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load wasm files as inline base64 data urls #753

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 0 additions & 2 deletions packages/upload-media/src/store/utils/vips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ const createVipsWorker = createWorkerFactory(
);
const vipsWorker = createVipsWorker();

void vipsWorker.setLocation( __webpack_public_path__ );

export async function vipsConvertImageFormat(
id: QueueItemId,
file: File,
Expand Down
10 changes: 0 additions & 10 deletions packages/vips/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,5 @@ _Returns_

- `Promise< { buffer: ArrayBuffer; width: number; height: number; originalWidth: number; originalHeight: number; } >`: Processed file data plus the old and new dimensions.

### setLocation

Dynamically sets the location / public path to use for loading the WASM files.

This is required when loading this module in an inline worker, where globals such as **webpack_public_path** are not available.

_Parameters_

- _newLocation_ `string`: Location, typically a base URL such as "<https://example.com/path/to/js/...">.


<!-- END TOKEN(Autogenerated API docs) -->
16 changes: 1 addition & 15 deletions packages/vips/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@
setDelayFunction: ( fn: ( fn: () => void ) => void ) => void;
}

let location = '';

/**
* Dynamically sets the location / public path to use for loading the WASM files.
*
* This is required when loading this module in an inline worker,
* where globals such as __webpack_public_path__ are not available.
*
* @param newLocation Location, typically a base URL such as "https://example.com/path/to/js/...".
*/
export function setLocation( newLocation: string ) {
location = newLocation;
}

let cleanup: () => void;

let vipsInstance: typeof Vips;
Expand All @@ -70,7 +56,7 @@
fileName = VipsJxlModule;
}

return location + fileName;
return fileName;

Check warning on line 59 in packages/vips/src/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/vips/src/index.ts#L59

Added line #L59 was not covered by tests
},
preRun: ( module: EmscriptenModule ) => {
// https://github.com/kleisauke/wasm-vips/issues/13#issuecomment-1073246828
Expand Down
7 changes: 1 addition & 6 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,7 @@ module.exports = {
},
{
test: /\.wasm$/,
type: 'asset/resource',
generator: {
// Use [contenthash:8] to help with cache busting.
filename: '[name].[contenthash:8].wasm',
publicPath: '',
},
type: 'asset/inline',
},
...defaultConfig.module.rules.slice( 1 ),
],
Expand Down
Loading