Bundler
A Go tool that bundles TypeScript scripts into a single
webview.js for each platform (Android and Xcode). Replaces the shell-based
esbuild tasks with a cross-platform binary that works on macOS, Linux, and
Windows.
Usage
From tools/bundler/src:
go run . --platform android \
--common lib/common/scripts \
--platform-dir lib/android/scripts \
--esbuild tools/vendor/esbuild/dist/esbuild-$(go env GOOS)-$(go env GOARCH) \
--tsconfig lib/common/config/bundler.json \
--output build/android/scripts/webview.js
Flags
| Flag | Required | Description |
|---|---|---|
|
Yes |
Target platform: |
|
Yes |
Path to common scripts directory ( |
|
Yes |
Path to platform-specific scripts ( |
|
Yes |
Path to the vendored esbuild binary. |
|
Yes |
Final output path for the bundled JS file. |
|
No |
Path to TypeScript config for the bundler. Default: |
|
No |
esbuild target. Default: |
|
No |
Banner comment prepended to output. Default: auto-generated comment. |
How it works
-
Creates a staging directory at
build/<platform>/jsandbuild/<platform>/scripts. -
Copies common scripts into
build/<platform>/scripts/. -
Copies platform-specific scripts on top (overrides common files with the same name).
-
Invokes the vendored esbuild binary via
os/execto bundlemain.tsintobuild/<platform>/js/main.js. -
Moves the result to
--outputpath. -
Cleans up staging directories.
All file operations use Go’s os and filepath packages, which are
cross-platform. No shell commands are used.
Script structure
lib/common/scripts/ # shared TypeScript, included in both platforms
lib/android/scripts/ # Android overrides (copied over common)
lib/xcode/scripts/ # Xcode overrides (copied over common)
TypeScript config for the bundler: lib/common/config/bundler.json.
Output
-
Xcode:
build/xcode/scripts/webview.js -
Android:
build/android/scripts/webview.js
A banner comment is prepended to mark the file as auto-generated.
Tasks
From the repository root:
-
task bundler(bn): bundle scripts for both Xcode and Android. -
task bundler.xcode(bx): bundle scripts for Xcode only. -
task bundler.android(ba): bundle scripts for Android only. -
task bundler.build(bb): build thetools/bundlerbinary.
From tools/bundler/src:
-
task build(b): cross-compile binaries into../dist/for macOS (amd64/arm64), Linux (amd64) and Windows (amd64). -
task test(t): run the test suite.
Release binaries
dist contains prebuilt binaries for each platform, named
bundler-<os>-<arch> (Windows uses .exe).
Bundle flags (esbuild)
The tool passes these flags to esbuild:
-
--bundle— resolves imports and produces a single output file. -
--target=safari11— output compatible with Safari 11+ (WKWebView). -
--analyze— prints a bundle size breakdown. -
--tsconfig— uses the specified TypeScript config for module resolution.