@swifttui/build
v0.1.6
Published
**Build tooling for [SwiftTUI](https://swifttui.sh) browser deployments — compile a SwiftTUI app to `wasm32-wasi` and capture its scene manifest.**
Readme
@swifttui/build
Build tooling for SwiftTUI browser deployments —
compile a SwiftTUI app to wasm32-wasi and capture its scene manifest.
@swifttui/build turns a SwiftTUI app into the two artifacts the browser needs:
an app.wasm and a scene-manifest.json. It drives the Swift toolchain, runs a
browser WebAssembly.compile validation pass, and packages the result. It
intentionally sits outside @swifttui/web
(the browser runtime) so runtime imports never pull in Swift process spawning,
Node filesystem APIs, or wasm packaging helpers.
- Runtime counterpart:
@swifttui/web— mounts the artifacts this package produces. - Reference template:
swift-tui-examples/WebExample - The framework:
SwiftTUI/swift-tui
Installation
Published to npm as an ESM package with a Node CLI and bundled TypeScript declarations:
npm install --save-dev @swifttui/buildThis exposes the swifttui-web CLI (npx swifttui-web build --app <Exe>) and a
programmatic ESM API. The package ships compiled dist/ JavaScript — the bin
runs on plain Node (#!/usr/bin/env node), no Bun or TypeScript toolchain
required to consume it. Building a SwiftTUI app to wasm does require a Swift
6.3.x toolchain and the swift-6.3.1-RELEASE_wasm SDK on your machine.
Use
From the command line:
npx swifttui-web build --app <AppExecutable>Or programmatically:
import { buildSwiftTUIWebApp } from "@swifttui/build";
await buildSwiftTUIWebApp({
packagePath: ".",
product: "MyApp",
outputDirectory: "dist",
});Toolchain defaults match the repo:
- Swift command:
swiftly run swiftwhenswiftlyis onPATH, otherwiseswift - SDK:
swift-6.3.1-RELEASE_wasm - Release Swift flags:
-Xswiftc -Osize -Xswiftc -Xfrontend -Xswiftc -disable-llvm-merge-functions-pass - Initial memory:
536870912 - Max memory:
4294967296 - Stack size:
1048576
Callers can override swiftCommand, swiftSDK, configuration,
initialMemory, maxMemory, stackSize, extraSwiftcFlags,
extraLinkerFlags, and extraSwiftBuildArgs.
The WASI release flags (
-Osizeplus-disable-llvm-merge-functions-pass) keep the output under the browserWebAssemblyAPI's 1000-parameter limit. The canonical command lives in this package — prefer the CLI/API over a hand-rolledswift build.
Developing this package
Only needed if you are working on
@swifttui/builditself. Consuming it from a project needs onlynpm install --save-dev(above).
Use Bun for the CLI, bundling, and tests, and swiftly Swift 6.3.1 for the wasm
build it invokes (not bare swift).
bun testbun run build— compile the publishable package todist/with tsdown (ESM.js+.d.ts, plus theswifttui-webbin). Run automatically on publish viaprepublishOnly.bun run build:manifest -- --app <AppExecutable>bun run build:wasm -- --app <AppExecutable>
The full app pipeline (manifest + wasm) is exposed through the CLI:
bun run cli.ts build --app <AppExecutable> # from source
npx swifttui-web build --app <AppExecutable> # from the published binLicense
MIT — see LICENSE.
