Make images smaller using best-in-class codecs, right in the browser.
JavaScript
Fixup import.meta in OxiPNG
Ingvar Stepanyan82fadac70e36
diff --git a/codecs/oxipng/build.sh b/codecs/oxipng/build.shindex 766fb4ba..a46bae68 100644--- a/codecs/oxipng/build.sh+++ b/codecs/oxipng/build.sh@@ -10,6 +10,7 @@ echo "============================================="rm -rf pkg,{-parallel}wasm-pack build -t webRUSTFLAGS='-C target-feature=+atomics,+bulk-memory' wasm-pack build -t web -d pkg-parallel -- -Z build-std=panic_abort,std --features=parallel+ sed -i "s|input = import.meta.url.replace(/\\\.js$/, '_bg.wasm');||" pkg{,-parallel}/oxipng.jsrm pkg{,-parallel}/.gitignore)echo "============================================="diff --git a/codecs/oxipng/pkg-parallel/oxipng.js b/codecs/oxipng/pkg-parallel/oxipng.jsindex e79e14c1..3d4a2566 100644--- a/codecs/oxipng/pkg-parallel/oxipng.js+++ b/codecs/oxipng/pkg-parallel/oxipng.js@@ -138,7 +138,7 @@ async function load(module, imports, maybe_memory) {async function init(input, maybe_memory) {if (typeof input === 'undefined') {- input = import.meta.url.replace(/\.js$/, '_bg.wasm');+}const imports = {};imports.wbg = {};diff --git a/codecs/oxipng/pkg/squoosh_oxipng.js b/codecs/oxipng/pkg/squoosh_oxipng.jsindex 74c98c89..a894a364 100644--- a/codecs/oxipng/pkg/squoosh_oxipng.js+++ b/codecs/oxipng/pkg/squoosh_oxipng.js@@ -94,7 +94,7 @@ async function load(module, imports) {async function init(input) {if (typeof input === 'undefined') {- input = import.meta.url.replace(/\.js$/, '_bg.wasm');+}const imports = {};imports.wbg = {};diff --git a/codecs/oxipng/spawn.ts b/codecs/oxipng/spawn.tsindex 5b1c15cf..bf62cf7b 100644--- a/codecs/oxipng/spawn.ts+++ b/codecs/oxipng/spawn.ts@@ -17,9 +17,9 @@ async function startMainThread() {const num = navigator.hardwareConcurrency;const workers = Array.from({ length: num }, () => new Worker('./worker', { type: 'module' }));await initOxiPNG(fetch(wasmUrl), undefined as any);- const workerInit: WorkerInit = worker_initializer();+ const workerInit: WorkerInit = worker_initializer(num);await Promise.all(workers.map(worker => initWorker(worker, workerInit)));- start_main_thread(num);+ start_main_thread();return {optimise,};