Closed joncrangle closed 7 months ago
I think it would be a good idea to make the build step in a separate directory, and compile the form into a single html file including tailwind. This way it can still be embedded into the binary. Also commit a default html into the repo, so that one could build the binary using just go, and without npm.
I played around with the concept a bit in a branch for demo purposes.
There is a build script that can be run with pnpm build
. It uses the Tailwind CLI to build the css and then minifies it into the /assets
directory. I used the Go Fiber Static
method to serve the /assets
directory, so this stylesheet can be used within the html as <link rel="stylesheet" href="/assets/styles.css">
.
Perhaps a Github action could run the build script whenever the form.html
page is changed to ensure that the stylesheet is updated with any Tailwind utlity classes that are required.
I think it’ll be better to serve the ‘assets/styles.css’ via a custom get handler in Go Fiber that serves a go:embed version of it. This way, the built tailwind styles are baked into the binary itself, rather than reaching into a directory (as the Static method does)
this would make deployment on edge systems simpler (IE: lambda, CF workers, etc) and be much more portable.
Thanks for the feedback. I've updated the branch to use go:embed and a get handler rather that the static method.
I needed some tweaks to let it run, but it works now.
The Tailwind Play CDN isn't recommended for production since it includes the whole Tailwind class library (large bundle). Proposal is to use the Tailwind CLI instead so that there is a css build step resulting in minified css of only the classes that are used (small bundle).
https://tailwindcss.com/docs/installation