This part isn’t required to use the project — but if you want to experiment with writing plugins in TypeScript, here’s how it works.
The downsides of writing plugins in TypeScript is mostly that your
.wasmfile will be much larger than the one compiled from rust or C:
- ~100KB of wasm for the rust plugin
- ~12MB of wasm for the TypeScript plugin
The reason is that a JavaScript runtime needs to be embedded in the
.wasmfile, which is not the case for the rust plugin.
More about the toolchain helps compile JS/TS code into WebAssembly components.
Build Steps
- Generate TypeScript types:
CODEcd packages/plugin-name
jco types --world-name plugin-api --out-dir ./src/types ../../crates/pluginlab/wit
- Bundle your TS code into a single file (using
rolldownor another bundler).
CODErolldown ./src/component.ts --file ./dist/component.js
- Componentize it:
CODEjco componentize ./dist/component.js \
--wit ../../crates/pluginlab/wit \
--world-name plugin-api \
--out ./dist/component.wasm \
--disable http --disable random
- (Optional) Optimize the resulting
.wasmfile:
CODEjco opt ./dist/component.wasm -o ./dist/component-opt.wasm
Example:package.jsonScripts
CODE{
"wit-types": "jco types ...",
"bundle": "rolldown ...",
"componentize": "jco componentize ...",
"build": "npm run wit-types && npm run bundle && npm run componentize",
"optimize": "jco opt ...",
"typecheck": "tsc --noEmit"
}
📎 Here are links to the implementation of the
plugin-echoplugin in TypeScript in the project.↗ Original-Artikel auf dev.to lesenVollständiger Original-BerichtAusführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
SOCIAL SHARE CARD GENERATOR