Documentation
¶
Overview ¶
Package webtool packages a Glutter app for the web (SPEC §23.1): it builds the program for js/wasm, writes the directory that a static web server can serve (index.html, wasm_exec.js, app.wasm and app.wasm.gz), and serves such a directory with the right types and with the gzip file for a browser that accepts it. cmd/glutter-web is its command line, and internal/webtest uses it to run apps in browsers.
Flutter: no counterpart (flutter build web, flutter run -d web-server).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AudioWorkletJS ¶
func AudioWorkletJS() string
AudioWorkletJS is the JavaScript of the audio worklet (SPEC §28.3): Build writes it as glutter-audio-worklet.js next to index.html, and the page loads it with audioWorklet.addModule when the app opens its first audio device.
Flutter: no counterpart
func CachingHandler ¶
CachingHandler is Handler for a build whose files the browser may keep for a while, as a site that is deployed would let it: the measurement of the start with app.wasm in the browser's cache (SPEC §15) needs it. A new build is not seen until the time is up.
Flutter: no counterpart
func Handler ¶
Handler serves the directory of a web build (SPEC §23.1): index.html for "/", every file with its type (app.wasm as application/wasm, which instantiateStreaming needs), and, to a browser that accepts gzip, app.wasm.gz in place of app.wasm with Content-Encoding gzip. The pages are cross-origin isolated (the COOP and COEP headers), which the audio worklet's shared ring needs (SPEC §28.3). Nothing outside the directory is reachable, and nothing is cached by the browser, so a new build is the one that loads.
Flutter: no counterpart
Types ¶
type BuildOptions ¶
type BuildOptions struct {
// Package is the main package to build, as `go build` takes it: "./examples/counter".
Package string
// OutDir is the directory to write the build to; it is created.
OutDir string
// Debug builds with -tags debug_mode (foundation.DebugMode) and does not strip the
// program; without it the build is a release, stripped with -ldflags=-s -w (SPEC §23.1).
Debug bool
// Dir is the directory to run the go command in, which Package is relative to. The
// default is the current directory.
Dir string
// HostElement is the CSS selector of the element the view fills; empty fills the page.
HostElement string
// Body is HTML for the body of index.html, before the loader: the host element when
// HostElement is set. Empty by default.
Body string
// Title is the title of index.html; the base name of Package when empty.
Title string
// Env is added to the environment of the go command.
Env []string
}
BuildOptions are the parameters of Build.
Flutter: no counterpart
type BuildResult ¶
type BuildResult struct {
// Dir is the directory of the build.
Dir string
// WasmSize and GzipSize are the sizes of app.wasm and app.wasm.gz in bytes.
WasmSize, GzipSize int64
}
BuildResult says what Build wrote, all in OutDir.
Flutter: no counterpart
func Build ¶
func Build(ctx context.Context, o BuildOptions) (*BuildResult, error)
Build builds the package for js/wasm with the standard Go toolchain (TinyGo is not supported, D18) and writes the directory that any static web server can serve (SPEC §23.1): index.html, glutter-audio-worklet.js (the audio worklet, SPEC §28.3), wasm_exec.js (copied from $(go env GOROOT)/lib/wasm, which must match the Go that builds), app.wasm and app.wasm.gz. It fails with WebBuildFailed when the go command fails (its output is in the error's metadata) and with WebWriteFailed when a file cannot be written.
Flutter: no counterpart (flutter build web)
type Page ¶
type Page struct {
// Title is the title of the page until the app sets its own.
Title string
// HostElement is the CSS selector for globalThis.glutterConfig.hostElement; empty
// leaves the view to fill the page (SPEC §23.2).
HostElement string
// Body is HTML put into the body before the loader: the host element of a page that
// embeds the app in an element of its own (SPEC §23.2).
Body string
}
Page describes the index.html of an app.
Flutter: no counterpart