Add build flag for production UI dist output embed.

This commit is contained in:
2025-01-25 18:41:34 -07:00
parent a3ac233f39
commit 8c8ec659a9
4 changed files with 34 additions and 21 deletions

View File

@@ -1,6 +1,6 @@
// +build !prod //go:build !prod
package server package main
import ( import (
"io/fs" "io/fs"
@@ -10,4 +10,3 @@ import (
func getUIAssets() fs.FS { func getUIAssets() fs.FS {
return os.DirFS("ui/dist") return os.DirFS("ui/dist")
} }

View File

@@ -1,20 +1,12 @@
// +build prod //go:build prod
package server package main
import ( import (
"embed" "github.com/smjklake/glancr/ui"
"io/fs" "io/fs"
) )
//go:embed frontend/dist func getUIAssets() fs.FS {
var embedFrontend embed.FS return ui.GetUIFS()
func getFrontendAssets() fs.FS {
f, err := fs.Sub(embedFrontend, "ui/dist")
if err != nil {
panic(err)
}
return f
} }

View File

@@ -1,5 +1,8 @@
package server package main
import "fmt"
func main() { func main() {
frontend := getUIAssets() frontend := getUIAssets()
fmt.Println(frontend)
} }

19
ui/embed.go Normal file
View File

@@ -0,0 +1,19 @@
package ui
import (
"embed"
"io/fs"
)
//go:embed dist
var embedUI embed.FS
/// GetUIFS returns an embed FS for the UI components in the dist dir.
func GetUIFS() fs.FS {
f, err := fs.Sub(embedUI, "build")
if err != nil {
panic(err)
}
return f
}