Skip to content

axle prune

Terminal window
axle prune <package>... [--out <folder>] [--docker] [--production]

A Docker image of one app doesn’t need the rest of the monorepo, but copying all of it means any change anywhere misses the image’s cache. axle prune writes a copy with only the packages you name, the workspace packages they depend on and a lockfile trimmed to match:

Wrote @acme/ui, @acme/utils, @acme/web into out: 214 files.
  • The packages you name, and every workspace package they depend on, directly or through others, as axle graph shows them. Each keeps every file Git tracks in its folder, and new files that .gitignore doesn’t ignore, so node_modules and build output stay out. A package inside another one’s folder is left out unless it’s kept too.
  • The files at the repository’s root, such as package.json, pnpm-workspace.yaml, .npmrc, axle.toml and tsconfig.json, but not the folders there, other than patches and .yarn without its cache and install state.
  • The lockfile, with only the entries the kept packages and the root use. pnpm-lock.yaml, aube-lock.yaml, nub.lock, package-lock.json, yarn.lock and bun.lock are trimmed; Bun’s older binary bun.lockb stops the prune with prune-failed, and Bun converts it with bun install --save-text-lockfile.

A symbolic link to a file the copy could hold anyway, one inside the repository that .gitignore doesn’t ignore, is copied as that file. Other links, links to folders and Git submodules are left out, so no file outside the repository or ignored by Git reaches the copy. A dependency on a folder that isn’t a workspace package, such as "foo": "file:../vendor/foo", isn’t copied either: make that folder a workspace package.

Installing in the copy with a frozen lockfile, such as pnpm install --frozen-lockfile, npm ci, yarn install --immutable (--frozen-lockfile with Yarn 1), bun install --frozen-lockfile, nub ci or aube ci, works without changing the lockfile. The workspace’s patterns, such as packages/*, stay as they are and match only the folders that are there.

--out is a new or empty folder, out by default, relative to the current folder. It can be inside the repository, where .gitignore should list it, but can’t be the repository, a folder around it or a folder inside .git. If writing fails, Axle removes what it wrote.

--docker splits the copy in two, so installing comes from Docker’s cache until a dependency changes:

  • out/json holds what installing needs: every package.json, the lockfile, pnpm-workspace.yaml, aube-workspace.yaml, nub.jsonc, .npmrc, .pnpmfile.cjs, .yarnrc, .yarnrc.yml, bunfig.toml, patches and .yarn.
  • out/full holds the whole copy.

With --docker, Axle ends with Wrote @acme/ui, @acme/utils, @acme/web into out: what installing needs in json, and all 214 files in full.

Copy out/json and install, then copy out/full over it and build:

FROM node:24-slim AS base
RUN corepack enable
FROM base AS prune
WORKDIR /repo
COPY . .
RUN pnpm dlx @axle-rs/axle prune @acme/web --docker
FROM base AS build
WORKDIR /repo
COPY --from=prune /repo/out/json/ .
RUN pnpm install --frozen-lockfile
COPY --from=prune /repo/out/full/ .
RUN pnpm exec axle run build --filter @acme/web

The build stage runs Axle from the copy’s own dependencies, so list @axle-rs/axle in the root package.json’s devDependencies and prune that stage without --production, and give the prune stage the same version, such as @axle-rs/axle@0.1.0. Keep node_modules, build output and out out of Docker’s context with a .dockerignore. When the context leaves .git out, or the image lacks Git, as node:24-slim and oven/bun do, Axle picks the files by .gitignore alone. The examples use Node.js 24 because it still ships Corepack; from Node.js 25 on, install it first with npm install --global corepack.

An image that only runs the app doesn’t need its build and test tools. --production leaves devDependencies out:

  • Each package.json in the copy, the root’s included, loses its devDependencies. A package listed there and also under dependencies or optionalDependencies stays.
  • A workspace package reached only through devDependencies isn’t kept. A dependency in axle.toml still keeps the package it names, unless that package is one of the devDependencies.
  • The lockfile keeps only what the kept packages and the root need without their devDependencies, and their own entries lose them too, so it matches the copy’s package.json files.

Installing in the copy with a frozen lockfile and the package manager’s production flag works without changing the lockfile:

Terminal window
pnpm install --frozen-lockfile --prod

Since the devDependencies are gone, a plain frozen install, such as pnpm install --frozen-lockfile or yarn install --immutable, installs the same. The copy can’t build what needs those tools, so build in a stage pruned without --production, and copy the build output into a stage pruned with it:

Wrote @acme/utils, @acme/web into out: 112 files, without devDependencies.

Hosting services such as Vercel and Netlify run a command to decide whether to build a project, and skip the build when it exits with 0. axle affected --exit-code exits with 1 when the app is affected and 0 when it isn’t.

Option What it does
--out <folder> the new or empty folder to write into, out by default
--docker writes what installing needs into json and the whole copy into full
--production leaves devDependencies out, and the lockfile entries only they need

Each problem has its own page: prune-folder-not-empty, prune-failed, unknown-package, could-not-read and file-not-written.