esbuildfs

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2023 License: MIT Imports: 14 Imported by: 0

README

ESBuild FS

Test

This plugin creates a simple in-memory Key-Value filesystem to track compiled assets to provide http.FileSystem support.

This is not designed for production, use it when development.

Usage

Install with go get

go get -u github.com/elct9620/esbuild-fs

The esbuildfs.Serve() shortcut is created to make assets handler and SSE (Server Sent Event).

assets, sse, err := esbuildfs.Server(
    api.BuildOptions{
        Outdir: "static/js", // required
        // ...
    },
    esbuildfs.WithPrefix("assets"), // Or `http.StripPrefix`
)

// ...
mux.Handle("/assets/", assets)
mux.Handle("/esbuild", sse)

We can use html/template to add the Live Reload script.

{{ if .LiveReload }}
<script>
    new EventSource('/esbuild').addEventListener('change', () => location.reload())
</script>
{{ end }}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFlasherUnsupported = errors.New("the flusher is not supported")

Functions

func Plugin

func Plugin(outdir string, writer Writer, options ...PluginOptionFn) (api.Plugin, error)

func Serve

func Serve(buildOptions api.BuildOptions, options ...PluginOptionFn) (http.Handler, http.Handler, error)

Types

type FS

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

func New

func New() *FS

func (*FS) Open

func (fsys *FS) Open(name string) (fs.File, error)

func (*FS) Write

func (fsys *FS) Write(name string, content io.Reader) error

type Notifier

type Notifier interface {
	NotifyChanged(updated []string) error
}

type PluginOptionFn

type PluginOptionFn = func(*fsPlugin)

func WithNotifier

func WithNotifier(notifier Notifier) PluginOptionFn

func WithPrefix

func WithPrefix(prefix string) PluginOptionFn

type ServerSentEventHandler

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

func NewSSE

func NewSSE() *ServerSentEventHandler

func (*ServerSentEventHandler) Broadcast

func (s *ServerSentEventHandler) Broadcast(event, data string)

func (*ServerSentEventHandler) NewStream

func (s *ServerSentEventHandler) NewStream() chan serverSentEvent

func (*ServerSentEventHandler) NotifyChanged

func (s *ServerSentEventHandler) NotifyChanged(updated []string) error

func (*ServerSentEventHandler) RemoveStream

func (s *ServerSentEventHandler) RemoveStream(stream chan serverSentEvent)

func (*ServerSentEventHandler) ServeHTTP

func (s *ServerSentEventHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

type Writer

type Writer interface {
	Write(name string, content io.Reader) error
}

Jump to

Keyboard shortcuts

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