[wasm] build: fix detection for environment
This commit is contained in:
parent
2cca297bcc
commit
59fafa9e2a
@ -92,9 +92,6 @@ async function main() {
|
|||||||
// Ask rollup to build bundles.
|
// Ask rollup to build bundles.
|
||||||
await run(['pnpm', 'build:bundle']);
|
await run(['pnpm', 'build:bundle']);
|
||||||
await run(['pnpm', 'exec', 'prettier', '--ignore-path', '', '-w', 'dist/loader.d.ts']);
|
await run(['pnpm', 'exec', 'prettier', '--ignore-path', '', '-w', 'dist/loader.d.ts']);
|
||||||
await replaceFileByRegex(path.join(wasmDistDir, 'loader.mjs'), [
|
|
||||||
['fetch(filepath)', 'fetch(new URL(filepath, import.meta.url))'],
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
@ -8,14 +8,15 @@ function loader() {
|
|||||||
initSync({ module: umWasm() });
|
initSync({ module: umWasm() });
|
||||||
return Promise.resolve(true);
|
return Promise.resolve(true);
|
||||||
} else {
|
} else {
|
||||||
/** @type {Promise<Buffer>|undefined} */
|
const url = new URL('um_wasm_bg.wasm', import.meta.url);
|
||||||
let wasm = undefined;
|
const wasm =
|
||||||
if (typeof document === 'undefined') {
|
url.protocol === 'file:'
|
||||||
// node
|
? import('node:f' + 's/promises')
|
||||||
wasm = import('node:f' + 's/promises').then((fs) =>
|
.then((fs) => fs.readFile(url))
|
||||||
fs.readFile(new URL('../pkg/um_wasm_bg.wasm', import.meta.url)),
|
.catch((err) => {
|
||||||
);
|
console.log('read wasm failed', err);
|
||||||
}
|
})
|
||||||
|
: undefined;
|
||||||
return __wbg_init({ module_or_path: wasm }).then(() => true);
|
return __wbg_init({ module_or_path: wasm }).then(() => true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user