Init fix.

This commit is contained in:
Leon Zandman 2026-05-10 00:26:47 +02:00
parent d31ef57131
commit 0d723d3e05
2 changed files with 17 additions and 1 deletions

View File

@ -22,7 +22,8 @@ let initPromise = null;
*/
export function zstdInit() {
if (!initPromise) {
initPromise = init();
const wasmUrl = `${self.docURL}/assets/zstd.wasm`;
initPromise = init(wasmUrl);
}
return initPromise;
}

View File

@ -99,6 +99,10 @@ module.exports = {
context: "node_modules/node-forge/dist",
from: "prime.worker.min.js",
to: "assets/forge/"
}, {
context: "node_modules/@bokuweb/zstd-wasm/dist/web/",
from: "zstd.wasm",
to: "assets/"
}
]
}),
@ -110,6 +114,17 @@ module.exports = {
operations: [
new ReplaceOperation("once", "if (pixelSize < elementMinSize)", "if (false)")
]
},
{
// @bokuweb/zstd-wasm's init() unconditionally evaluates
// `new URL("./zstd.wasm", import.meta.url)` before checking
// whether a path was passed in. Webpack's `publicPath: ""`
// makes that base URL invalid and the constructor throws.
// Neuter the offending line; we always pass a path from Zstd.mjs.
test: /@bokuweb[\/\\]zstd-wasm[\/\\]dist[\/\\]web[\/\\]index\.web\.js$/,
operations: [
new ReplaceOperation("once", "new URL(`./zstd.wasm`, import.meta.url).href", "''")
]
}
]
})