4 ms·
You can use go’s builtin build features and embed the results into a http.FS. go generate npm build go build And declaring the resulting frontend build as
by reactordev 2y ago
You can use go’s builtin build features and embed the results into a http.FS.
go generate npm build
go build
And declaring the resulting frontend build as an embed.FS using
//go:embed dist/
var frontend *embed.FS
And use that in a http.FS
https://blog.logrocket.com/using-go-generate-reduce-boilerplate-code/ https://blog.logrocket.com/using-go-generate-reduce-boilerpl...
- peter_l_downs 2y agoYeah this is what I do to. The OP's approach is interesting but I think that using typescript/javascript/whatever to build your app, then "render" using a build step (like `vite build` or whatever) and embedding the resulting static bundles is the best of both worlds. That said, the JS ecosystem is so weird that I totally understand the urge to bail entirely and do things in Go. But JS/TS and all the related frameworks really are decent if you pick a reasonable subset of them.
- irq-1 2y agoYou can also use `go generate` to create all the .html routes/handlers at compile. Not that it would matter much in a small app.