Use native Wasm+Webpack support for Rust codecs

This delegates loading of Wasm modules to Webpack itself, making wrapper code simpler.

Emscripten-generated modules are still using custom loading glue as they're not compatible with Webpack.
This commit is contained in:
Ingvar Stepanyan
2019-08-05 14:50:18 +01:00
parent b8f801333d
commit 8e857cd393
14 changed files with 100 additions and 308 deletions

View File

@@ -1,24 +1,12 @@
import wasmUrl from '../../../codecs/hqx/pkg/squooshhqx_bg.wasm';
import '../../../codecs/hqx/pkg/squooshhqx';
import { resize } from '../../../codecs/hqx/pkg';
import { HqxOptions } from './processor-meta';
interface WasmBindgenExports {
resize: typeof import('../../../codecs/hqx/pkg/squooshhqx').resize;
}
type WasmBindgen = ((url: string) => Promise<void>) & WasmBindgenExports;
declare var wasm_bindgen: WasmBindgen;
const ready = wasm_bindgen(wasmUrl);
export async function hqx(
data: ImageData,
opts: HqxOptions,
): Promise<ImageData> {
const input = data;
await ready;
const result = wasm_bindgen.resize(
const result = resize(
new Uint32Array(input.data.buffer),
input.width,
input.height,