frontend

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithBundler

func WithBundler(cfg *esbuild.Config) application.Option

WithBundler returns an application.Option that uses the esbuild bundler. This is the recommended way to configure the frontend for library mode.

Example:

application.New(views,
    frontend.WithBundler(&esbuild.Config{
        Entry:   "components/index.ts",
        Include: []string{"components"},
    }),
)

Types

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

Controller is the frontend controller that handles component bundling and serving.

func (*Controller) Handle

Handle implements the Controller interface (required but not used for frontend).

func (*Controller) Setup

func (c *Controller) Setup(app *application.App)

Setup is called when the controller is registered with the application. It builds the components and registers routes.

type Frontend

type Frontend struct {
	SourceDir string // Default: "components"
	OutputDir string // Default: "views/static/scripts/gen"
	DevMode   bool   // Enable HMR and file watching
	// contains filtered or unexported fields
}

Frontend manages JavaScript component islands within HTMX-driven pages.

func New

func New() *Frontend

New creates a new Frontend instance.

func (*Frontend) Build

func (f *Frontend) Build() error

Build compiles all components in SourceDir to OutputDir. Requires a bundler configured via WithBundler. Safe for concurrent calls — serialized to prevent overlapping esbuild runs.

func (*Frontend) Controller

func (f *Frontend) Controller() (string, *Controller)

Controller returns a named controller that integrates the frontend bundler with the application.

func (*Frontend) Dev

func (f *Frontend) Dev() error

Dev starts the development server with file watching and HMR.

func (*Frontend) Render

func (f *Frontend) Render(name string, props any) template.HTML

Render returns an island container for the named component. Props are JSON-serialized into data-props attribute.

func (*Frontend) Script

func (f *Frontend) Script(nonce string) template.HTML

Script returns the runtime script tags for templates. This includes mount orchestration and HMR client in development. The nonce parameter is injected into all generated <script> tags for CSP compliance.

func (*Frontend) Stop

func (f *Frontend) Stop()

Stop stops the development server and file watcher.

Directories

Path Synopsis
Package esbuild provides a bundler for frontend components using esbuild's Go API.
Package esbuild provides a bundler for frontend components using esbuild's Go API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL