f411b90 Added example 006 for using esbuild
~mariusor pushed to ~mariusor/assets git
A library to help with the management of serving static files.
It builds on top of any Go's standard fs.FS
interface implementation and, it provides a method to overlay
a different file structure on top of what the underlying fs exposes. We call this an "asset group".
It includes its own fs.FS
implementation, which can be generated using //go:generate
, and has a small advantage
over the standard //go:embed
mechanism by providing an API to pipeline functionality at resource compile time.
It currently supports filtering out files, and processing the remaining ones using a simple API.
See the examples folder for ways to use this.
DirFS
fsThe asset group maps one to one with the files in the example's ./static
folder.
DirFS
fs.In this example the exposed entries of the asset group are each composed of multiple "pieces",
each of them represented by a file in the ./static
folder:
/main.js
├─ ./static/js/hello.js
└─ ./static/js/world.js
This is an example closer to real world usage where we embed the contents of the files in the ./static
folder
using //go:embed
if we run/compile the example using the prod
build tag, or we use the DirFS
method we saw in example 1.
This example was born out of the need of adding some processing steps for the contents of the files, which can not be
done using the standard //go:embed
method.
In our case we chose to minify the CSS stylesheets, JavaScript files and the SVG document in the ./static
folder.
Instead of requiring the asset group in the consumer code, we can generate it directly containing our desired structure.
We bundle all the following files into just one that can be accessed at /main.js
:
./static/
└── js
├── assets.js
├── group.js
└── hello.js
This example shows how to use the packing functionality to actually run an existing web bundler for compiling a typescript file into a desired javascript.