Skip to content

Build executor

The build executor compiles a Go program into an executable using go build.

nx build my-go-app
OptionTypeDefaultDescription
mainstring-Relative path from the project root to the main.go file defining the binary.
compilergo | tinygo | gowgoThe Go compiler to use.
outputPathstring-The output path of the resulting executable.
buildModestring-The build mode to use.
envobject-Environment variables to set when running the executor.
flagsstring[]-Flags to pass to the go compiler.

When main is set, the build runs from the directory containing that main.go file. When omitted, the build targets ./... (all packages in the project tree).

Inferred for projects containing a main package (applications). The plugin generates:

{
  "executor": "@naxodev/gonx:build",
  "cache": true,
  "dependsOn": ["generate"],
  "inputs": ["{projectRoot}/go.mod", "{projectRoot}/go.sum", "{projectRoot}/**/*.{go}"],
  "options": {
    "outputPath": "dist/{projectRoot}/"
  },
  "outputs": ["{options.outputPath}"]
}

The default outputPath resolves to dist/<projectRoot>/. Override it via the outputPath option.