@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.
[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 inexposes, preserving the filename.dist/knit.manifest.json— the completed manifest withspec,name,exposes,shared(including SRIintegrityfor each shared asset), and ametablock withbuildTimeand detectedframework.
Example
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
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
knitkit-remotes.d.ts looks like:
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).