-
-
Notifications
You must be signed in to change notification settings - Fork 5
feat: scaffold v1 #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v1
Are you sure you want to change the base?
Conversation
moved ui stuffs to ui package changed frontend build to ui/build embedded build files for serve serve command now serves embedded files dev command runs inertia in dev mode
Changed Files
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is good, it is just that inertia.go for vite already handle most of the parts.
* | ||
!.gitignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add ui/build
folder to gitignore, you can put a .gitkeep to ui/build/.gitkeep if you want,
inertia, err := gonertia.NewFromBytes(ui.BuildHtml()) | ||
if err != nil { | ||
panic(err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use inertia.NewFromFileFS(embedFS, "...")
https://github.com/romsar/gonertia?tab=readme-ov-file#basic-example
in, err := gonertia.NewFromFile("ui/views/app.html") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
i, err := inertia.NewWithVite(in) | ||
if err != nil { | ||
log.Fatal(err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for dual func, the inertia.go for vite handle both cases.
//go:embed views/app.html | ||
var buildHtml []byte | ||
|
||
func BuildHtml() []byte { | ||
return buildHtml[:] | ||
} | ||
|
||
//go:embed build | ||
var build embed.FS | ||
|
||
func Assets() fs.FS { | ||
assets, err := fs.Sub(build, "build/assets") | ||
if err != nil { | ||
panic(fmt.Errorf("failed to get subdirectory %q: %w", "build/assets", err)) | ||
} | ||
|
||
return assets | ||
} | ||
|
||
//go:embed build/manifest.json | ||
var manifest []byte | ||
|
||
type manitestData map[string]struct { | ||
File string `json:"file"` | ||
} | ||
|
||
func Manifest() func(name string) (string, error) { | ||
var data manitestData | ||
err := json.Unmarshal(manifest, &data) | ||
if err != nil { | ||
panic(fmt.Errorf("failed to unmarshal manifest: %w", err)) | ||
} | ||
|
||
return func(name string) (string, error) { | ||
entry, ok := data[name] | ||
if !ok { | ||
return "", fmt.Errorf("entry %q not found in manifest", name) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to handle all of this, as it already handled in the inertia.go for vite
we can have a simple:
//go:embed public/*
var embeddedUI embed.FS
subFS, err := fs.Sub(embeddedFiles, "ui")
and use http.FileServer with it
Can use the ViteConfig with Options Pattern to override behaviour which points to public right now.
cmdServe := &cobra.Command{ | ||
Use: "serve", | ||
Short: "Start the explorer server", | ||
RunE: serveCommand(logger, "127.0.0.1", 1337, false), | ||
} | ||
|
||
cmdDev := &cobra.Command{ | ||
Use: "dev", | ||
Short: "Start the explorer server in development mode", | ||
RunE: serveCommand(logger, "127.0.0.1", 1337, true), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inertia.go for vite already knows if it is dev or not, it detect the hot file. if it exists, it will call vite for assets to do hot reload. If it doesn't see hot file, it will serve the assets directly.
Scaffold for Golang with inertiaJS