Skip to main content
The knitkit CLI (@knitkit/cli) automates the build-side half of module federation: it bundles each shared package to an ESM asset via esbuild, copies your exposed modules, computes sha384 SRI hashes, writes dist/knit.manifest.json, and provides separate subcommands for generating TypeScript declarations from your exposed modules and syncing types from remote manifests into your host application. Install it as a development dependency and run commands from the root of your federated micro-frontend.
All commands accept an optional [cwd] argument that overrides the working directory. When omitted, the current working directory is used.

knitkit build [cwd]

knitkit build reads knit.config.json from the project root, bundles each package listed in shared to a self-contained ESM file using esbuild, copies each path listed in exposes into dist/exposes/, computes a sha384 SRI hash for every shared asset, and writes the completed dist/knit.manifest.json.

knit.config.json fields

The build command reads its configuration from knit.config.json in the working directory.

Output structure

  • dist/shared/<pkg>-<version>.js — esbuild output for each shared package, named with the installed version so URLs are cache-safe.
  • dist/exposes/<file> — a direct copy of each path declared in exposes, preserving the filename.
  • dist/knit.manifest.json — the completed manifest with spec, name, exposes, shared (including SRI integrity for each shared asset), and a meta block with buildTime and detected framework.

Example

Example manifest output:
requiredVersion is automatically set to ^<version> (caret range) by the build command. If you need a stricter or looser range, edit the manifest after building or patch it in your deployment pipeline.

knitkit types generate [cwd]

knitkit types generate uses the project’s installed TypeScript compiler to emit a .d.ts declaration file for each exposed module and writes the files to dist/types/. It then patches dist/knit.manifest.json in place, setting the types field on each matching exposes entry to point at the generated declaration. Run this command after knitkit build, since it reads and patches the manifest that build produces.

Output

The patched manifest entry looks like:
knitkit types generate requires typescript to be installed in your project. Install it with npm i -D typescript if it is not already present. The command uses the TypeScript compiler API directly — no tsconfig.json is required, though one is respected if present in your project.

knitkit types sync [cwd]

knitkit types sync reads knit.host.json from the working directory, fetches each listed remote’s manifest, downloads the .d.ts files referenced in each exposes[].types field, and writes a knitkit-remotes.d.ts declaration that augments the RemoteModules interface in @knitkit/runtime. After syncing, loadRemote("checkout/CartWidget") returns a properly typed value.

knit.host.json fields

Example knit.host.json:

Output

The generated knitkit-remotes.d.ts looks like:
Add the typesDir directory to your tsconfig.json include array so TypeScript picks up the augmentation:
Only remotes whose exposes entries include a types field are synced. Run knitkit types generate on your remote project first to populate that field.

knitkit validate <manifest>

knitkit validate reads a manifest JSON file from disk and validates it against the knitkit manifest spec using the same validateManifest function that @knitkit/runtime uses at runtime. Use it in CI pipelines or pre-deploy checks to catch manifest errors before they reach the browser.
string
required
Path to the manifest file to validate (e.g. dist/knit.manifest.json).

Exit codes

Example output

Successful validation:
Failed validation:
Add knitkit validate dist/knit.manifest.json as a step after knitkit build in your CI workflow. It catches version string errors, missing required fields, and spec mismatches before the manifest is deployed.