Web & UI/Assets, Images & JS Pipelines

Assets, Images & JS Pipelines

Zero-Node esbuild and Tailwind v4, import maps, opt-in Vite with npm/pnpm/bun, and <f:img> image transforms.

github.com/fletchhq/fletch/assets· fletch docs show assets-and-images

On this page

Fletch ships three front-end asset modes alongside a pure-Go image processing pipeline. New applications default to zero-Node esbuild and Tailwind v4, with scaffolds for native ES module import maps and opt-in Vite via npm, pnpm, or Bun.

Choosing a JavaScript Pipeline

Tier Scaffold Command Runtime Dependency Output Style
Tier 1: esbuild + Tailwind v4 (default) fletch new myapp or --js esbuild None (pure Go) Fingerprinted bundles + manifest.json
Tier 2: Native ES Module Import Maps fletch new myapp --js importmap None (pure Go) Unbundled ES modules + <script type="importmap">
Tier 3: Opt-In Vite fletch new myapp --js vite --pm npm|pnpm|bun Node / pnpm / Bun Vite 8 + TypeScript app in web/

.fletch/scaffold.json records js and package_manager so fletch upgrade and fletch upgrade --adopt preserve your chosen front-end mode across framework updates.

Tier 1: Zero-Node assets/pipeline and Tailwind v4

The default pipeline runs without Node, Bun, or npm. assets/pipeline wraps pure-Go asset transformers and Tailwind v4 compilation behind pipeline.New(root, opts...).

Configuring assets/pipeline

Build a pipeline with pipeline.New(root, opts...) and register transformers from github.com/fletchhq/fletch/assets/pipeline:

p := pipeline.New(".",
	pipeline.WithTransformers(
		pipeline.ESBuild("."),
		pipeline.CSSImports(),
		pipeline.Copy(),
	),
)

Use pipeline.ESBuild(root) from assets/pipeline (there is no assets.Esbuild helper in package assets). Available pipeline options and transformers:

Function Purpose
pipeline.New(root, opts...) Constructs the asset build pipeline rooted at root.
pipeline.WithTransformers(...) Replaces or sets the ordered list of asset transformers.
pipeline.WithoutTailwind() Disables Tailwind v4 compilation for projects using plain CSS.
pipeline.WithDevDir(dir) Sets the working output directory used during development builds.
pipeline.ESBuild(root) Bundles and minifies JS/TS entrypoints in resources/.
pipeline.CSSImports() Resolves and inlines @import statements in CSS files.
pipeline.Copy() Copies static assets verbatim into the output tree with fingerprinting.
pipeline.Tailwind(root, opts...) Runs Tailwind v4; accepts pipeline.TailwindMirror, pipeline.TailwindCacheDir, and pipeline.TailwindPin.

Building Assets and Resolving Manifests

Run the CLI builder to compile, fingerprint, minify, compress, and write manifest.json:

fletch assets build --src resources --out public/dist

Both flags default to --src resources and --out public/dist.

At runtime, load the generated manifest into an assets.Resolver and attach it to request contexts:

manifest, err := assets.ReadManifest(distFS)
if err != nil {
	return err
}

resolver := assets.NewFSResolver(distFS, manifest, assets.WithCDN("https://cdn.example.com"))

// Attach to each request context in middleware
ctx = assets.NewContext(ctx, resolver)

// Retrieve inside handlers or Crest helpers
r, ok := assets.FromContext(ctx) // ok is false when no resolver is attached

Tier 2: Native ES Module Import Maps

For applications that prefer unbundled browser ES modules with zero Node tooling, scaffold with --js importmap:

fletch new myapp --js importmap

This creates resources/app/main.js and resources/app/greet.js. Files live under resources/app/ instead of resources/js/ so the default esbuild bundler leaves them untouched as individual ES modules.

Create the resolver with assets.ImportMap(fsys, opts...), which returns an *assets.ImportMapResolver providing ImportMapTag(ctx) and ImportMapHTML(). In ui/layouts/app.crest, render the map and module entrypoint with:

<assets.ImportMapTags entry="app/main" />

When FLETCH_DEV=1 is set, the scaffolded resolver serves files directly from resources/, so JavaScript edits take effect on browser refresh without rebuilding public/dist.

Tier 3: Opt-In Vite with npm, pnpm, or Bun

Applications that need a full Vite ecosystem (TypeScript, React/Vue/Svelte islands, or npm packages) can opt into Vite during scaffolding:

fletch new myapp --js vite --pm bun
# Also supported: --pm npm (default), --pm pnpm

Passing --pm requires --js vite. The scaffold performs four wiring steps:

  1. Creates web/ containing package.json (Vite 8 + TypeScript), vite.config.ts, tsconfig.json, src/main.ts, and src/style.css.
  2. Adds web/node_modules/ and web/dist/ to .gitignore.
  3. Configures bootstrap/assets.go with assets.Vite(assets.ViteRoot("web"), assets.ViteRuntime("bun"), ...).
  4. Renders <assets.ViteTags entry="src/main.ts" /> inside ui/layouts/app.crest.

Runtime and Lockfile Detection

assets.ViteRuntime accepts "npm", "pnpm", or "bun". If you omit assets.ViteRuntime (or pass an empty string), Fletch inspects web/ for lockfiles in order:

Lockfile Detected Runtime
bun.lock or bun.lockb bun
pnpm-lock.yaml pnpm
package-lock.json npm

assets vs. assets/pipeline Vite Options

Keep the runtime resolver options in package assets distinct from the build/CLI options in package assets/pipeline:

Package Functions Role
assets assets.Vite, assets.ViteRoot, assets.ViteRuntime, assets.ViteDevServer(baseURL) Runtime manifest/dev-server resolver used by bootstrap/assets.go and <assets.ViteTags />.
assets/pipeline pipeline.NewVite, pipeline.ViteDevServer(baseURL), pipeline.ViteCommand, pipeline.ViteDevCommand, pipeline.ViteDevLog CLI and build pipeline integration for running Vite production builds and dev server processes.

Atomic Production Rebuilds

Vite builds compile into a temporary staging directory first and swap into public/dist atomically only when the build succeeds. A broken TypeScript or bundler build leaves the previous valid public/dist intact.

Image Processing (images and <f:img>)

The github.com/fletchhq/fletch/images package handles on-the-fly resizing, format conversion, signed transform URLs, and variant caching in pure Go, with optional native libvips acceleration or hosted CDN offloading.

Configuring images.New

imgService := images.New(
	images.WithPresets(presets),
	images.WithMaxPixels(25_000_000),
	images.WithMaxBytes(15<<20),
	images.WithSignedTransforms(signingKey),
	images.WithVariants(images.DiskVariants("storage/images")),
	images.WithSource(images.StaticSource(publicFS)),
	images.WithConcurrency(4),
)
Option Purpose
images.WithPresets(...) Registers named size/format presets referenced by <f:img>.
images.WithMaxPixels(n) Caps decoded source image pixel count to guard memory usage.
images.WithMaxBytes(n) Caps maximum source file byte size.
images.WithSignedTransforms(key) Signs transform URLs with HMAC to block arbitrary resize abuse.
images.WithProcessor(p) Swaps the image encoder/decoder (for example, images/vips).
images.WithVariants(store) Sets variant cache storage: images.MemoryVariants() or images.DiskVariants(dir).
images.WithSource(src) Registers image loaders: images.StaticSource, images.StorageSource, or images.RemoteSource.
images.WithRemote(origins...) Allowlists remote host origins for remote image fetching.
images.WithConcurrency(n) Limits concurrent image transform workers.
images.WithAuthorizer(fn) Enforces request-level access control before serving private images.

Image References and <f:img>

Construct typed references matching your registered sources:

  • images.Static(path) for bundled or public/ static files
  • images.Stored(key) for objects fetched through a storage backend
  • images.Remote(url) for allowlisted external URLs

In Crest templates, <f:img> consumes a preset or dimensions and emits a responsive <picture> element with content-negotiated formats and srcset URLs pointing at the image handler:

<f:img src={images.Stored(post.CoverKey)} preset="card" alt={post.Title} />

Swapping Processors, Prewarming, and Hosted CDNs

The core images module compiles with CGO_ENABLED=0. For high-throughput workloads or external offload, swap in a standalone module without changing templates:

  • images/vips: CGO libvips processor passed via images.WithProcessor(...) for faster transforms and lower memory overhead on heavy media workloads.
  • images/prewarm: pre-generates preset variants eagerly (for example, from a Quiver background job after upload) so the first browser request hits warm cache.
  • Hosted transform providers: images.Imgproxy, images.CloudflareImages, and images.Cloudinary rewrite <f:img> URLs directly to your hosted image CDN.