You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/README.mbt.md
+43-18Lines changed: 43 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,8 +4,8 @@ Type-safe MoonBit bindings for Web Platform APIs, automatically generated from W
4
4
5
5
## Table of Contents
6
6
7
-
-[Overview](#overview)
8
7
-[Installation](#installation)
8
+
-[Overview](#overview)
9
9
-[Quick Start](#quick-start)
10
10
-[Counter Example](#counter-example)
11
11
-[WebSocket Example](#websocket-example)
@@ -21,7 +21,7 @@ Type-safe MoonBit bindings for Web Platform APIs, automatically generated from W
21
21
-[Custom Elements](#custom-elements)
22
22
-[Method Chaining](#method-chaining)
23
23
-[Optional Parameters](#optional-parameters)
24
-
-[Trimming webapi.mjs for Production](#trimming-webapimjs-for-production)
24
+
-[Trimming webapi.mjs for wasm-gc Production](#trimming-webapimjs-for-wasm-gc-production)
25
25
-[WebIDL to MoonBit Conversion](#webidl-to-moonbit-conversion)
26
26
-[Type Mappings](#type-mappings)
27
27
-[Interface Generation](#interface-generation)
@@ -32,6 +32,20 @@ Type-safe MoonBit bindings for Web Platform APIs, automatically generated from W
32
32
-[Building from Source](#building-from-source)
33
33
-[License](#license)
34
34
35
+
## Installation
36
+
37
+
Add this package to your MoonBit project:
38
+
39
+
```bash
40
+
moon add bikallem/webapi@0.4.2
41
+
```
42
+
43
+
To also install the `webapitrim` CLI tool (for trimming `webapi.mjs` in wasm-gc deployments):
44
+
45
+
```bash
46
+
moon add --bin bikallem/webapi
47
+
```
48
+
35
49
## Overview
36
50
37
51
This library provides MoonBit FFI bindings for browser APIs including:
@@ -58,14 +72,6 @@ This library provides MoonBit FFI bindings for browser APIs including:
58
72
59
73
All bindings are automatically generated from official WebIDL specifications, ensuring type safety and API completeness.
60
74
61
-
## Installation
62
-
63
-
Add this package to your MoonBit project:
64
-
65
-
```bash
66
-
moon add bikallem/webapi@0.4.2
67
-
```
68
-
69
75
## Quick Start
70
76
71
77
### Counter Example
@@ -376,21 +382,40 @@ fn readme_optional() -> Unit {
376
382
}
377
383
```
378
384
379
-
## Trimming webapi.mjs for Production
385
+
## Trimming webapi.mjs for wasm-gc Production
386
+
387
+
The full `src/webapi.mjs` JS runtime (~8,400 lines) contains modules for every supported Web API. For **wasm-gc** deployments, the `webapitrim` tool produces a minimal version containing only the modules your `.wasm` binary actually imports — typically 500–1,000 lines (~90% smaller).
380
388
381
-
The full `webapi/webapi.mjs` JS runtime (~8,400 lines) contains modules for every supported Web API. For wasm-gc deployments, `webapi_trim` produces a minimal version containing only the modules your `.wasm` binary actually imports — typically 500–1,000 lines (~90% smaller).
389
+
> **Note:** This tool is only relevant for the wasm-gc backend. The JS backend does not use `webapi.mjs`.
390
+
391
+
### Installing webapitrim
392
+
393
+
Install the `webapitrim` CLI via the MoonBit package manager:
394
+
395
+
```bash
396
+
moon add --bin bikallem/webapi
397
+
```
398
+
399
+
This installs the `webapitrim` binary to `~/.moon/bin/` (or your configured MoonBit bin directory).
382
400
383
401
### Usage
384
402
385
403
```bash
386
404
# Trim for a single wasm binary (output: webapi.mjs next to the .wasm file)
387
-
make trim WASM=examples/_build/wasm-gc/release/build/counter/counter.wasm
@@ -412,7 +437,7 @@ Point your wasm-gc HTML page at the trimmed file instead of the full bundle:
412
437
413
438
### How It Works
414
439
415
-
`webapi_trim` parses the wasm binary's import section to find which `webapi_` JS modules are referenced, then extracts only those modules (plus the shared `wasmImportObject` export) from the full `webapi.mjs`. No runtime behavior changes — just fewer unused modules shipped to the browser.
440
+
`webapitrim` parses the wasm binary's import section to find which `webapi_` JS modules are referenced, then extracts only those modules (plus the shared `wasmImportObject` export) from the full `webapi.mjs`. No runtime behavior changes — just fewer unused modules shipped to the browser.
0 commit comments