diff options
author | Alexander Neonxp Kiryukhin <i@neonxp.ru> | 2024-10-29 01:21:05 +0300 |
---|---|---|
committer | Alexander Neonxp Kiryukhin <i@neonxp.ru> | 2024-10-29 01:21:05 +0300 |
commit | fd4e0c3112d69061d495dfcf79f6ef62e3c6d5e6 (patch) | |
tree | fa55d6e879e3c6d85601d5c2486837f323ffd81d /cmd/frontend/frontend.go | |
parent | b26bd10926447ed59cbf263aef087bb7c04f35eb (diff) |
Diffstat (limited to 'cmd/frontend/frontend.go')
-rw-r--r-- | cmd/frontend/frontend.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/cmd/frontend/frontend.go b/cmd/frontend/frontend.go new file mode 100644 index 0000000..9679d6f --- /dev/null +++ b/cmd/frontend/frontend.go @@ -0,0 +1,68 @@ +package frontend + +import ( + "errors" + "log" + + "github.com/evanw/esbuild/pkg/api" + "github.com/urfave/cli/v2" +) + +var FrontendCommand *cli.Command = &cli.Command{ + Name: "frontend", + Description: "Build/watch frontend", + Action: func(c *cli.Context) error { + dev := c.Bool("dev") + watch := c.Bool("watch") + buildOpts := api.BuildOptions{ + EntryPoints: []string{ + "./web/src/index.js", + "./web/src/index.css", + "./web/src/index.html", + }, + Outdir: "./web/dist", + Bundle: true, + Write: true, + MinifyWhitespace: !dev, + MinifyIdentifiers: !dev, + MinifySyntax: !dev, + JSX: api.JSXAutomatic, + Loader: map[string]api.Loader{ + ".js": api.LoaderJSX, + ".css": api.LoaderCSS, + ".html": api.LoaderCopy, + }, + } + if watch { + ctx, err := api.Context(buildOpts) + if err != nil { + return err + } + if err := ctx.Watch(api.WatchOptions{}); err != nil { + return err + } + log.Println("watching frontend") + <-c.Done() + } else { + if br := api.Build(buildOpts); br.Errors != nil { + for _, e := range br.Errors { + log.Println(e.Location, e.Detail, e.Text) + } + + return errors.New("build failed") + } + } + + return nil + }, + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "dev", + Value: false, + }, + &cli.BoolFlag{ + Name: "watch", + Value: false, + }, + }, +} |