summaryrefslogtreecommitdiff
path: root/cmd/frontend/frontend.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/frontend/frontend.go')
-rw-r--r--cmd/frontend/frontend.go68
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,
+ },
+ },
+}