Compare commits
2 Commits
2cca297bcc
...
3cdb14fc96
Author | SHA1 | Date | |
---|---|---|---|
3cdb14fc96 | |||
59fafa9e2a |
@ -92,9 +92,6 @@ async function main() {
|
||||
// Ask rollup to build bundles.
|
||||
await run(['pnpm', 'build:bundle']);
|
||||
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()
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@unlock-music/crypto",
|
||||
"version": "0.0.0-alpha.5",
|
||||
"version": "0.0.0-alpha.6",
|
||||
"description": "Project Unlock Music: 加解密支持库",
|
||||
"scripts": {
|
||||
"build": "node build.js",
|
||||
|
@ -8,14 +8,15 @@ function loader() {
|
||||
initSync({ module: umWasm() });
|
||||
return Promise.resolve(true);
|
||||
} else {
|
||||
/** @type {Promise<Buffer>|undefined} */
|
||||
let wasm = undefined;
|
||||
if (typeof document === 'undefined') {
|
||||
// node
|
||||
wasm = import('node:f' + 's/promises').then((fs) =>
|
||||
fs.readFile(new URL('../pkg/um_wasm_bg.wasm', import.meta.url)),
|
||||
);
|
||||
}
|
||||
const url = new URL('um_wasm_bg.wasm', import.meta.url);
|
||||
const wasm =
|
||||
url.protocol === 'file:'
|
||||
? import('node:f' + 's/promises')
|
||||
.then((fs) => fs.readFile(url))
|
||||
.catch((err) => {
|
||||
console.log('read wasm failed', err);
|
||||
})
|
||||
: undefined;
|
||||
return __wbg_init({ module_or_path: wasm }).then(() => true);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user