https://github.com/elct9620/esbuild-fs
The esbuild plugin to support Go's http.FileServer
https://github.com/elct9620/esbuild-fs
esbuild-plugin golang
Last synced: 10 months ago
JSON representation
The esbuild plugin to support Go's http.FileServer
- Host: GitHub
- URL: https://github.com/elct9620/esbuild-fs
- Owner: elct9620
- License: mit
- Created: 2023-07-08T06:34:01.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-09T17:38:13.000Z (almost 3 years ago)
- Last Synced: 2025-01-28T09:49:01.724Z (over 1 year ago)
- Topics: esbuild-plugin, golang
- Language: Go
- Homepage:
- Size: 29.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ESBuild FS
===
[](https://github.com/elct9620/esbuild-fs/actions/workflows/test.yml)
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`
```bash
go get -u github.com/elct9620/esbuild-fs
```
The `esbuildfs.Serve()` shortcut is created to make assets handler and SSE (Server Sent Event).
```go
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.
```html
{{ if .LiveReload }}
new EventSource('/esbuild').addEventListener('change', () => location.reload())
{{ end }}
```