axle prune
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.What the copy holds
Section titled “What the copy holds”- The packages you name, and every workspace package they depend on, directly or through others, as
axle graphshows them. Each keeps every file Git tracks in its folder, and new files that.gitignoredoesn’t ignore, sonode_modulesand 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.tomlandtsconfig.json, but not the folders there, other thanpatchesand.yarnwithout 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.lockandbun.lockare trimmed; Bun’s older binarybun.lockbstops the prune withprune-failed, and Bun converts it withbun 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.
For Docker
Section titled “For Docker”--docker splits the copy in two, so installing comes from Docker’s cache until a dependency changes:
out/jsonholds what installing needs: everypackage.json, the lockfile,pnpm-workspace.yaml,aube-workspace.yaml,nub.jsonc,.npmrc,.pnpmfile.cjs,.yarnrc,.yarnrc.yml,bunfig.toml,patchesand.yarn.out/fullholds 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 baseRUN corepack enable
FROM base AS pruneWORKDIR /repoCOPY . .RUN pnpm dlx @axle-rs/axle prune @acme/web --docker
FROM base AS buildWORKDIR /repoCOPY --from=prune /repo/out/json/ .RUN pnpm install --frozen-lockfileCOPY --from=prune /repo/out/full/ .RUN pnpm exec axle run build --filter @acme/webFROM node:24-slim AS pruneWORKDIR /repoCOPY . .RUN npx @axle-rs/axle prune @acme/web --docker
FROM node:24-slim AS buildWORKDIR /repoCOPY --from=prune /repo/out/json/ .RUN npm ciCOPY --from=prune /repo/out/full/ .RUN npx axle run build --filter @acme/webFROM node:24-slim AS baseRUN corepack enable
FROM base AS pruneWORKDIR /repoCOPY . .RUN yarn dlx @axle-rs/axle prune @acme/web --docker
FROM base AS buildWORKDIR /repoCOPY --from=prune /repo/out/json/ .RUN yarn install --immutableCOPY --from=prune /repo/out/full/ .RUN yarn axle run build --filter @acme/webWith Yarn 1, run Axle in the prune stage with npx instead of yarn dlx, and install with yarn install --frozen-lockfile.
FROM oven/bun:1 AS pruneWORKDIR /repoCOPY . .RUN bunx @axle-rs/axle prune @acme/web --docker
FROM oven/bun:1 AS buildWORKDIR /repoCOPY --from=prune /repo/out/json/ .RUN bun install --frozen-lockfileCOPY --from=prune /repo/out/full/ .RUN bunx axle run build --filter @acme/webFROM node:24-slim AS baseRUN npm install --global @nubjs/nub
FROM base AS pruneWORKDIR /repoCOPY . .RUN nub dlx @axle-rs/axle prune @acme/web --docker
FROM base AS buildWORKDIR /repoCOPY --from=prune /repo/out/json/ .RUN nub ciCOPY --from=prune /repo/out/full/ .RUN nubx axle run build --filter @acme/webFROM node:24-slim AS baseRUN npm install --global --ignore-scripts=false @endevco/aube
FROM base AS pruneWORKDIR /repoCOPY . .RUN aube dlx @axle-rs/axle prune @acme/web --docker
FROM base AS buildWORKDIR /repoCOPY --from=prune /repo/out/json/ .RUN aube ciCOPY --from=prune /repo/out/full/ .RUN aube exec axle run build --filter @acme/webThe 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.
Without devDependencies
Section titled “Without devDependencies”An image that only runs the app doesn’t need its build and test tools. --production leaves devDependencies out:
- Each
package.jsonin the copy, the root’s included, loses itsdevDependencies. A package listed there and also underdependenciesoroptionalDependenciesstays. - A workspace package reached only through
devDependenciesisn’t kept. A dependency inaxle.tomlstill keeps the package it names, unless that package is one of thedevDependencies. - 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’spackage.jsonfiles.
Installing in the copy with a frozen lockfile and the package manager’s production flag works without changing the lockfile:
pnpm install --frozen-lockfile --prodnpm ci --omit=devyarn workspaces focus --all --productionWith Yarn 1, yarn install --frozen-lockfile --production.
bun install --frozen-lockfile --productionnub install --frozen-lockfile --prodaube install --frozen-lockfile --prodSince 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.Deploying only what changed
Section titled “Deploying only what changed”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.
Options
Section titled “Options”| 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.