Documentation
¶
Index ¶
- func InlineCSS(content string) g.Node
- func InlineCSSWithAttrs(content string, attrs ...g.Node) g.Node
- func InlineScript(content string) g.Node
- func InlineScriptWithAttrs(content string, attrs ...g.Node) g.Node
- type Config
- type DevServer
- type ESBuildProcessor
- func (ep *ESBuildProcessor) FileTypes() []string
- func (ep *ESBuildProcessor) Name() string
- func (ep *ESBuildProcessor) Process(ctx context.Context, cfg ProcessorConfig) error
- func (ep *ESBuildProcessor) WithBundle(bundle bool) *ESBuildProcessor
- func (ep *ESBuildProcessor) WithEntryPoints(entries ...string) *ESBuildProcessor
- func (ep *ESBuildProcessor) WithExternal(external ...string) *ESBuildProcessor
- func (ep *ESBuildProcessor) WithFormat(format string) *ESBuildProcessor
- func (ep *ESBuildProcessor) WithOutfile(path string) *ESBuildProcessor
- func (ep *ESBuildProcessor) WithSplitting(splitting bool) *ESBuildProcessor
- func (ep *ESBuildProcessor) WithTarget(target string) *ESBuildProcessor
- func (ep *ESBuildProcessor) WithVerbose(verbose bool) *ESBuildProcessor
- type EmbeddedManager
- type Manager
- func (m *Manager) Build(ctx context.Context) error
- func (m *Manager) FingerprintAll() error
- func (m *Manager) Handler() http.Handler
- func (m *Manager) HotReloadScript() string
- func (m *Manager) IsDev() bool
- func (m *Manager) Pipeline() *Pipeline
- func (m *Manager) PreloadScript(path string, opts ...ScriptOption) g.Node
- func (m *Manager) PreloadStyleSheet(path string, opts ...StyleOption) g.Node
- func (m *Manager) PublicDir() string
- func (m *Manager) SSEHandler() any
- func (m *Manager) SaveManifest(path string) error
- func (m *Manager) Script(path string, opts ...ScriptOption) g.Node
- func (m *Manager) StartDevServer(ctx context.Context) error
- func (m *Manager) StopDevServer() error
- func (m *Manager) StyleSheet(path string, opts ...StyleOption) g.Node
- func (m *Manager) URL(path string) string
- type Manifest
- type Pipeline
- type PipelineConfig
- type Processor
- type ProcessorConfig
- type ScriptEntry
- type ScriptManager
- func (sm *ScriptManager) Add(entry ScriptEntry)
- func (sm *ScriptManager) AddInline(content string, priority int, position string)
- func (sm *ScriptManager) AddWithPriority(path string, priority int, attrs map[string]string)
- func (sm *ScriptManager) Clear()
- func (sm *ScriptManager) Count() int
- func (sm *ScriptManager) CountByPosition(position string) int
- func (sm *ScriptManager) Render(position string) []g.Node
- type ScriptOption
- type StyleOption
- type TailwindProcessor
- func (tp *TailwindProcessor) FileTypes() []string
- func (tp *TailwindProcessor) Name() string
- func (tp *TailwindProcessor) Process(ctx context.Context, cfg ProcessorConfig) error
- func (tp *TailwindProcessor) WithConfigPath(path string) *TailwindProcessor
- func (tp *TailwindProcessor) WithContentPaths(paths []string) *TailwindProcessor
- func (tp *TailwindProcessor) WithInputCSS(path string) *TailwindProcessor
- func (tp *TailwindProcessor) WithOutputCSS(path string) *TailwindProcessor
- func (tp *TailwindProcessor) WithVerbose(verbose bool) *TailwindProcessor
- type WatchCallback
- type Watcher
- func (w *Watcher) AddPath(path string) error
- func (w *Watcher) AddPattern(pattern string)
- func (w *Watcher) Close() error
- func (w *Watcher) OnChange(callback WatchCallback)
- func (w *Watcher) SetDebounce(duration time.Duration)
- func (w *Watcher) SetVerbose(verbose bool)
- func (w *Watcher) Start(ctx context.Context) error
- func (w *Watcher) WatchDirectory(dir string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InlineCSSWithAttrs ¶
InlineCSSWithAttrs creates a <style> element with inline CSS and custom attributes
func InlineScript ¶
InlineScript creates a <script> element with inline JavaScript content
Types ¶
type Config ¶
type Config struct {
// PublicDir is the source directory for static assets (e.g., "public")
PublicDir string
// OutputDir is the output directory for processed assets (e.g., "dist")
OutputDir string
// IsDev enables development mode (no fingerprinting)
IsDev bool
// Manifest is the path to a manifest file for production builds
Manifest string
}
Config defines configuration options for asset management
type DevServer ¶
type DevServer struct {
// contains filtered or unexported fields
}
DevServer provides development features like hot reload and file watching. It watches for file changes and notifies connected browsers via Server-Sent Events (SSE).
func NewDevServer ¶
NewDevServer creates a new development server
func (*DevServer) ClientCount ¶
ClientCount returns the number of connected SSE clients
func (*DevServer) HotReloadScript ¶
HotReloadScript returns the client-side JavaScript for hot reload
func (*DevServer) SSEHandler ¶
func (ds *DevServer) SSEHandler() http.HandlerFunc
SSEHandler returns an HTTP handler for Server-Sent Events
func (*DevServer) SetVerbose ¶
SetVerbose enables verbose logging
type ESBuildProcessor ¶
type ESBuildProcessor struct {
// EntryPoints are the JavaScript entry files to bundle
EntryPoints []string
// Outfile is the output bundle file path (relative to output directory)
Outfile string
// Format specifies the output format ("iife", "cjs", "esm")
Format string
// Target specifies the JavaScript target (e.g., "es2020")
Target string
// Bundle enables bundling of dependencies
Bundle bool
// Splitting enables code splitting (requires format: "esm")
Splitting bool
// External are packages to exclude from bundling
External []string
// Verbose enables detailed logging
Verbose bool
}
ESBuildProcessor bundles and minifies JavaScript files using esbuild. It's optional for SSR applications but useful for custom JavaScript.
func NewESBuildProcessor ¶
func NewESBuildProcessor() *ESBuildProcessor
NewESBuildProcessor creates a new ESBuild processor with sensible defaults
func (*ESBuildProcessor) FileTypes ¶
func (ep *ESBuildProcessor) FileTypes() []string
FileTypes returns the file extensions this processor handles
func (*ESBuildProcessor) Name ¶
func (ep *ESBuildProcessor) Name() string
Name returns the processor name
func (*ESBuildProcessor) Process ¶
func (ep *ESBuildProcessor) Process(ctx context.Context, cfg ProcessorConfig) error
Process executes the ESBuild bundling
func (*ESBuildProcessor) WithBundle ¶
func (ep *ESBuildProcessor) WithBundle(bundle bool) *ESBuildProcessor
WithBundle enables or disables bundling
func (*ESBuildProcessor) WithEntryPoints ¶
func (ep *ESBuildProcessor) WithEntryPoints(entries ...string) *ESBuildProcessor
WithEntryPoints sets the JavaScript entry points
func (*ESBuildProcessor) WithExternal ¶
func (ep *ESBuildProcessor) WithExternal(external ...string) *ESBuildProcessor
WithExternal sets packages to exclude from bundling
func (*ESBuildProcessor) WithFormat ¶
func (ep *ESBuildProcessor) WithFormat(format string) *ESBuildProcessor
WithFormat sets the output format
func (*ESBuildProcessor) WithOutfile ¶
func (ep *ESBuildProcessor) WithOutfile(path string) *ESBuildProcessor
WithOutfile sets the output bundle file path
func (*ESBuildProcessor) WithSplitting ¶
func (ep *ESBuildProcessor) WithSplitting(splitting bool) *ESBuildProcessor
WithSplitting enables code splitting
func (*ESBuildProcessor) WithTarget ¶
func (ep *ESBuildProcessor) WithTarget(target string) *ESBuildProcessor
WithTarget sets the JavaScript target
func (*ESBuildProcessor) WithVerbose ¶
func (ep *ESBuildProcessor) WithVerbose(verbose bool) *ESBuildProcessor
WithVerbose enables verbose logging
type EmbeddedManager ¶
type EmbeddedManager struct {
*Manager
// contains filtered or unexported fields
}
EmbeddedManager extends Manager to work with embed.FS
func NewEmbeddedManager ¶
func NewEmbeddedManager(embedFS fs.FS, cfg Config) *EmbeddedManager
NewEmbeddedManager creates a manager that serves assets from an embedded filesystem
func (*EmbeddedManager) EmbeddedHandler ¶
func (m *EmbeddedManager) EmbeddedHandler() http.Handler
EmbeddedHandler returns an http.Handler for serving embedded static files
func (*EmbeddedManager) FingerprintAllEmbedded ¶
func (m *EmbeddedManager) FingerprintAllEmbedded() error
FingerprintAllEmbedded generates fingerprints for all embedded assets
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles static assets with caching and fingerprinting
func NewManager ¶
NewManager creates a new asset manager with the given configuration
func (*Manager) Build ¶
Build runs the asset pipeline to process all assets. This is typically used for production builds.
func (*Manager) FingerprintAll ¶
FingerprintAll generates fingerprints for all assets in the public directory
func (*Manager) HotReloadScript ¶
HotReloadScript returns the client-side JavaScript for hot reload. Include this in your HTML during development.
func (*Manager) Pipeline ¶
Pipeline returns the asset pipeline for this manager. Creates a new pipeline if one doesn't exist.
func (*Manager) PreloadScript ¶
func (m *Manager) PreloadScript(path string, opts ...ScriptOption) g.Node
PreloadScript creates a <link rel="preload"> element for a JavaScript file
func (*Manager) PreloadStyleSheet ¶
func (m *Manager) PreloadStyleSheet(path string, opts ...StyleOption) g.Node
PreloadStyleSheet creates a <link rel="preload"> element for a CSS file
func (*Manager) SSEHandler ¶
SSEHandler returns the Server-Sent Events handler for hot reload. Mount this at /_forgeui/reload in your HTTP server. Returns nil if dev server is not running.
func (*Manager) SaveManifest ¶
SaveManifest writes the current fingerprint mappings to a manifest file
func (*Manager) Script ¶
func (m *Manager) Script(path string, opts ...ScriptOption) g.Node
Script creates a <script> element for a JavaScript file
func (*Manager) StartDevServer ¶
StartDevServer starts the development server with hot reload. This watches for file changes and automatically rebuilds assets.
func (*Manager) StopDevServer ¶
StopDevServer stops the development server if running
func (*Manager) StyleSheet ¶
func (m *Manager) StyleSheet(path string, opts ...StyleOption) g.Node
StyleSheet creates a <link> element for a CSS file
type Manifest ¶
Manifest represents a mapping of original asset paths to fingerprinted paths
func GenerateManifest ¶
GenerateManifest creates a manifest from all assets in a directory
func LoadManifest ¶
LoadManifest loads a manifest from a JSON file
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline orchestrates multiple asset processors in sequence. It ensures processors run in the correct order and handles errors gracefully.
func NewPipeline ¶
func NewPipeline(cfg PipelineConfig, manager *Manager) *Pipeline
NewPipeline creates a new asset pipeline with the given configuration
func (*Pipeline) AddProcessor ¶
AddProcessor adds a processor to the pipeline. Processors are executed in the order they are added.
func (*Pipeline) Build ¶
Build executes all processors in sequence. If any processor fails, the build stops and returns the error.
func (*Pipeline) Config ¶
func (p *Pipeline) Config() PipelineConfig
Config returns the pipeline configuration
func (*Pipeline) ProcessorCount ¶
ProcessorCount returns the number of processors in the pipeline
func (*Pipeline) Processors ¶
Processors returns a copy of the processor list
type PipelineConfig ¶
type PipelineConfig struct {
// InputDir is the source directory for all assets
InputDir string
// OutputDir is the destination directory for processed assets
OutputDir string
// IsDev enables development mode (no minification, faster builds)
IsDev bool
// Minify enables minification of assets in production
Minify bool
// SourceMaps enables source map generation
SourceMaps bool
// Watch enables file watching for automatic rebuilds
Watch bool
// CleanOutput removes the output directory before building
CleanOutput bool
// Verbose enables detailed logging
Verbose bool
}
PipelineConfig defines the pipeline's overall configuration
type Processor ¶
type Processor interface {
// Name returns the processor name for logging and debugging
Name() string
// Process executes the asset processing with the given configuration
Process(ctx context.Context, cfg ProcessorConfig) error
// FileTypes returns the file extensions this processor handles (e.g., [".css", ".js"])
FileTypes() []string
}
Processor processes assets (CSS, JS, images, etc.) Implementations can handle different asset types and transformations.
type ProcessorConfig ¶
type ProcessorConfig struct {
// InputDir is the source directory for assets
InputDir string
// OutputDir is the destination directory for processed assets
OutputDir string
// IsDev indicates if running in development mode
IsDev bool
// Minify enables minification of assets
Minify bool
// SourceMaps enables source map generation
SourceMaps bool
// Watch enables file watching for automatic rebuilds
Watch bool
// CustomConfig allows processors to receive custom configuration
CustomConfig map[string]any
}
ProcessorConfig contains configuration for asset processing
type ScriptEntry ¶
type ScriptEntry struct {
// Path is the URL or file path to the script
Path string
// Priority determines load order (0-100, lower loads first)
// Typical values:
// 0-19: Critical framework scripts (Alpine.js, etc.)
// 20-49: Library dependencies
// 50-79: Application scripts
// 80-100: Analytics, third-party widgets
Priority int
// Position determines where the script is rendered ("head" or "body")
Position string
// Inline indicates if this is an inline script (Content is used instead of Path)
Inline bool
// Content is the inline script content (only used if Inline is true)
Content string
// Attrs are additional HTML attributes (defer, async, type, etc.)
Attrs map[string]string
}
ScriptEntry represents a script with metadata for ordering and rendering. Scripts can be inline or external, and are prioritized for optimal loading.
type ScriptManager ¶
type ScriptManager struct {
// contains filtered or unexported fields
}
ScriptManager manages script loading order and rendering. It ensures scripts are loaded in the correct order based on priority and prevents duplicate script tags.
func NewScriptManager ¶
func NewScriptManager() *ScriptManager
NewScriptManager creates a new script manager
func (*ScriptManager) Add ¶
func (sm *ScriptManager) Add(entry ScriptEntry)
Add adds a script entry to the manager. Duplicate paths are ignored (first occurrence wins).
func (*ScriptManager) AddInline ¶
func (sm *ScriptManager) AddInline(content string, priority int, position string)
AddInline adds an inline script with the given content
func (*ScriptManager) AddWithPriority ¶
func (sm *ScriptManager) AddWithPriority(path string, priority int, attrs map[string]string)
AddWithPriority is a convenience method to add a script with a specific priority
func (*ScriptManager) Clear ¶
func (sm *ScriptManager) Clear()
Clear removes all scripts from the manager
func (*ScriptManager) Count ¶
func (sm *ScriptManager) Count() int
Count returns the total number of scripts
func (*ScriptManager) CountByPosition ¶
func (sm *ScriptManager) CountByPosition(position string) int
CountByPosition returns the number of scripts in a specific position
type ScriptOption ¶
type ScriptOption func(*scriptConfig)
ScriptOption is a functional option for configuring script elements
func WithNoModule ¶
func WithNoModule() ScriptOption
WithNoModule sets the nomodule attribute for a script
func WithScriptCrossOrigin ¶
func WithScriptCrossOrigin(value string) ScriptOption
WithScriptCrossOrigin sets the crossorigin attribute for a script
func WithScriptIntegrity ¶
func WithScriptIntegrity(hash string) ScriptOption
WithScriptIntegrity sets the integrity hash (SRI) for a script
type StyleOption ¶
type StyleOption func(*styleConfig)
StyleOption is a functional option for configuring stylesheet elements
func WithCrossOrigin ¶
func WithCrossOrigin(value string) StyleOption
WithCrossOrigin sets the crossorigin attribute for a stylesheet
func WithIntegrity ¶
func WithIntegrity(hash string) StyleOption
WithIntegrity sets the integrity hash (SRI) for a stylesheet
func WithMedia ¶
func WithMedia(media string) StyleOption
WithMedia sets the media attribute for a stylesheet
type TailwindProcessor ¶
type TailwindProcessor struct {
// ConfigPath is the path to tailwind.config.js (auto-generated if empty)
ConfigPath string
// InputCSS is the path to the input CSS file with @tailwind directives
InputCSS string
// OutputCSS is the path where processed CSS will be written
OutputCSS string
// ContentPaths are glob patterns for files to scan for classes
// Defaults to ["**/*.go"] to scan all Go files
ContentPaths []string
// UseCDN falls back to CDN if Tailwind CLI is not available
UseCDN bool
// Verbose enables detailed logging
Verbose bool
}
TailwindProcessor processes Tailwind CSS by scanning Go files for class usage and generating optimized CSS output.
func NewTailwindProcessor ¶
func NewTailwindProcessor() *TailwindProcessor
NewTailwindProcessor creates a new Tailwind CSS processor with sensible defaults
func (*TailwindProcessor) FileTypes ¶
func (tp *TailwindProcessor) FileTypes() []string
FileTypes returns the file extensions this processor handles
func (*TailwindProcessor) Name ¶
func (tp *TailwindProcessor) Name() string
Name returns the processor name
func (*TailwindProcessor) Process ¶
func (tp *TailwindProcessor) Process(ctx context.Context, cfg ProcessorConfig) error
Process executes the Tailwind CSS processing
func (*TailwindProcessor) WithConfigPath ¶
func (tp *TailwindProcessor) WithConfigPath(path string) *TailwindProcessor
WithConfigPath sets a custom tailwind.config.js path
func (*TailwindProcessor) WithContentPaths ¶
func (tp *TailwindProcessor) WithContentPaths(paths []string) *TailwindProcessor
WithContentPaths sets custom content paths to scan for classes
func (*TailwindProcessor) WithInputCSS ¶
func (tp *TailwindProcessor) WithInputCSS(path string) *TailwindProcessor
WithInputCSS sets a custom input CSS file
func (*TailwindProcessor) WithOutputCSS ¶
func (tp *TailwindProcessor) WithOutputCSS(path string) *TailwindProcessor
WithOutputCSS sets the output CSS file path (relative to output directory)
func (*TailwindProcessor) WithVerbose ¶
func (tp *TailwindProcessor) WithVerbose(verbose bool) *TailwindProcessor
WithVerbose enables verbose logging
type WatchCallback ¶
WatchCallback is called when files change
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher watches files for changes and triggers callbacks. It uses fsnotify for cross-platform file system notifications.
func (*Watcher) AddPattern ¶
AddPattern adds a glob pattern for file matching
func (*Watcher) OnChange ¶
func (w *Watcher) OnChange(callback WatchCallback)
OnChange registers a callback for file changes
func (*Watcher) SetDebounce ¶
SetDebounce sets the debounce duration for file changes
func (*Watcher) SetVerbose ¶
SetVerbose enables verbose logging
func (*Watcher) WatchDirectory ¶
WatchDirectory recursively watches a directory and its subdirectories