中文

Tooling

Configure, run, bundle, and continuously rebuild func projects with funcgo.

Updated 2 weeks ago

func is the command runtime; funcgo is its project tool. It does three jobs: inspect package configuration, execute a TypeScript entry for local development, and bundle that entry into an executable production directory. It does not decide your command model or generate application help.

Projects created automatically from the default template already include funcgo. For any other project, install it as a development dependency before using the commands on this page:

Terminal
npm install --save-dev funcgo

Use the package scripts for the normal path, and invoke funcgo directly when you need a custom file, output, external dependency, or watch target.

Inspect configuration with setup

funcgo setup reads the current package.json and prints missing or differing recommendations. Without --fix, it makes no changes.

Terminal
funcgo setup
funcgo setup --fix

--fix can write func.entry, func.outDir, a bin mapping, and the conventional dev and build scripts. Use it for a new CLI package. In an existing application package, review the suggestions first because those generic script names may already belong to the host application.

Setup detects src/index.ts or index.ts when present. If it cannot find an entry, it recommends src/index.ts; create that file before expecting dev or build to work.

Run TypeScript once with dev

funcgo dev starts Node.js with a local TypeScript runtime and executes the resolved entry. Everything after -- is passed unchanged as the CLI’s argument array.

Terminal
funcgo dev -- greet --name Ada
funcgo dev -f src/cli/index.ts -- --help

The -f/--file option chooses a different entry without changing package configuration. dev runs once and exits; it does not watch source files. Repeat the command while editing, or use build watch with a globally linked executable as described in the Quick Start.

Create a production bundle

funcgo build bundles the resolved entry and its reachable dependencies, writes index.js to the output directory, and creates an executable bin.js that loads it.

Terminal
funcgo build
funcgo build -f src/cli/index.ts -o dist/cli
funcgo build -e react -e ink

Use -f/--file for a custom entry and -o/--out for an isolated output. Each -e/--external leaves one package outside the bundle. An external package must still be available to users at runtime, so keep it in package dependencies and include it in the distribution plan.

Rebuild when inputs change

--watch keeps the build process open. It performs an initial bundle, then rebuilds after matching file changes. By default it watches src/**/*.ts.

Terminal
funcgo build --watch
funcgo build --watch --watch-path 'src/**/*.ts' --watch-path config.json

Repeat --watch-path for every additional file, directory, or positive glob. A custom watch path replaces the default set, so include the TypeScript glob explicitly when adding a configuration file. --watch-path requires --watch. Negative globs are not supported, and the output directory, node_modules, and .git are ignored to prevent rebuild loops.

Understand resolution order

SettingHighest to lowest priority
Entry file--file / -f → package.json#func.entry → src/index.ts → index.ts
Build output--out / -o → package.json#func.outDir → dist
Watch targetsEvery --watch-path → src/**/*.ts when no custom path is supplied

Command-line overrides are useful for experiments and secondary entries. Store the normal package contract in package.json so local development, CI, global linking, and publishing agree:

package.json
{
  "scripts": {
    "dev": "funcgo dev --",
    "build": "funcgo build"
  },
  "func": {
    "entry": "src/index.ts",
    "outDir": "dist"
  },
  "bin": {
    "ship": "./dist/bin.js"
  }
}

The bin key is the command users type; its value must point to the generated bin.js inside the chosen output directory. See the API Reference for the compact option list.