Nic*_*all 6 rollup typescript webassembly wasm-bindgen
使用汇总,我试图捆绑一个 typescript 库,该库导入和调用包含 wasm 文件的 npm 模块。
只有生成的包不包含 wasm 文件内容的痕迹。我怎样才能强制它也捆绑 webassembly?
这是我尝试过的关键文件:
// typescript/src/index.ts
import * as libEd from "ed25519-raw";
export const seed_from_phrase = libEd.seed_from_phrase;
export const gen_keypair = libEd.gen_keypair;
Run Code Online (Sandbox Code Playgroud)
我的 package.json 是
{
"name": "ed25519",
"version": "0.1.0",
"description": "ed25519",
"main": "typescript/dist/bundle.cjs.js",
"types": "typescript/src/index.ts",
"dependencies": {
"ed25519-raw": "git+https://github.com/cmanteiga/ed25519-raw"
},
"devDependencies": {
"@types/node": "^13.7.1",
"typescript": "^3.7.5",
"@rollup/plugin-commonjs": "^11.0.2",
"@rollup/plugin-multi-entry": "^3.0.0",
"@rollup/plugin-node-resolve": "^7.1.1",
"@rollup/plugin-wasm": "^3.0.0",
"rollup": "^1.31.1",
"rollup-plugin-typescript2": "^0.26.0"
}
}
Run Code Online (Sandbox Code Playgroud)
最后汇总配置是
{
"name": "ed25519",
"version": "0.1.0",
"description": "ed25519",
"main": "typescript/dist/bundle.cjs.js",
"types": "typescript/src/index.ts",
"dependencies": {
"ed25519-raw": "git+https://github.com/cmanteiga/ed25519-raw"
},
"devDependencies": {
"@types/node": "^13.7.1",
"typescript": "^3.7.5",
"@rollup/plugin-commonjs": "^11.0.2",
"@rollup/plugin-multi-entry": "^3.0.0",
"@rollup/plugin-node-resolve": "^7.1.1",
"@rollup/plugin-wasm": "^3.0.0",
"rollup": "^1.31.1",
"rollup-plugin-typescript2": "^0.26.0"
}
}
Run Code Online (Sandbox Code Playgroud)
(完整的示例存储库可在https://github.com/nmrshll/ed25519 获得)
然后通过生成包 node node_modules/.bin/rollup -c
它包含一个function _loadWasmModule (sync, src, imports)但从未被调用过的,并且没有嵌入式 webassembly 的痕迹(我希望它是一个硬编码的 base64 字符串)。
我怎样才能解决这个问题 ?
编辑:包含在“ed25519-raw”中的 wasm 文件是wasm-pack使用选项生成的--target web
这很重要,因为wasm-pack使用选项--target browser(默认)运行会生成不同的输出(嵌入了 wasm 但有编译问题)
| 归档时间: |
|
| 查看次数: |
508 次 |
| 最近记录: |