Add post build command and exclude the esbuild outdir in the watcher.

This commit is contained in:
2024-07-04 10:56:41 +02:00
parent c356f34e21
commit 30f8be3d5d
4 changed files with 34 additions and 7 deletions

View File

@ -1,7 +1,9 @@
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"github.com/evanw/esbuild/pkg/api"
@ -34,6 +36,19 @@ func buildAction(ctx *cli.Context) error {
api.Build(o.ESBuild.BuildOptions)
replace(o)
if ctx.Bool("p") && o.ProductionBuildOptions.CmdPostBuild != "" {
fmt.Printf("Executing post production build command `%s`\n", o.ProductionBuildOptions.CmdPostBuild)
cmd := exec.Command("sh", "-c", o.ProductionBuildOptions.CmdPostBuild)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
fmt.Printf("Failed to execute post production build command `%s`: %+v\n", o.ProductionBuildOptions.CmdPostBuild, err)
os.Exit(1)
}
}
}
return nil