Skip to content

Build Executor

Terminal window
nx build my-go-app
OptionTypeDefaultDescription
mainstring-Relative path from the project root to the main.go file defining the binary
compilerstring”go”The Go compiler to use (possible values: ‘go’, ‘tinygo’)
outputPathstringdist/{project-root}The output path of the resulting executable
buildModestring-Build mode to use
envobject-Environment variables to set when running the executor
flagsstring[]-Flags to pass to the go compiler
{
"executor": "@naxodev/gonx:build",
"cache": true,
"inputs": ["{projectRoot}/go.mod", "{projectRoot}/go.sum", "{projectRoot}/**/*.{go}"],
"options": {
"outputPath": "dist/{projectRoot}"
},
"outputs": ["{options.outputPath}"]
}
Terminal window
nx build my-go-app
Terminal window
nx build my-go-app --main=cmd/server/main.go

This will build the application using the main.go file located at cmd/server/main.go relative to the project root.

  • The build executor is cacheable, so subsequent builds with the same inputs will be faster
  • Uses the official Go compiler in the background by default but the compiler can be overridden to use tinygo or any other Go compiler
  • When main option is specified, the build command runs from the directory containing the main.go file
  • If no main option is provided, the build command will discover and build all main packages in the project