logo
Parslinks
Back to blog
Deploy5 min read

Deploying a monorepo: Turborepo, pnpm workspaces and the project root

One repo with several apps is great, as long as a one-line CSS change to the site doesn't rebuild the dashboard too.

Alireza Tadi

Co-founder, Parslinks · Team, marketing & infrastructure

The Parslinks website, its dashboard and their shared component library live in one repo: apps/web, apps/dashboard and packages/ui, with pnpm workspaces and Turborepo. When the team changes a button in packages/ui, both apps must rebuild. When only the About page copy in apps/web changes, building the dashboard is wasted time.

This post uses that structure as the example, because we work with it every day.

The example layout

tree
repo/
├─ apps/
│  ├─ web/          # site and blog (Next.js)
│  └─ dashboard/    # user dashboard (Next.js)
├─ packages/
│  ├─ ui/           # shared components
│  └─ i18n/         # Persian and English messages
├─ pnpm-workspace.yaml
├─ pnpm-lock.yaml
└─ turbo.json
bash10 lines

One project per app on the platform

The common mistake is treating the whole repo as one project. Every deployable app is its own project with its own settings:

Deploy settings for two apps from one monorepo

The key point: install from the repo root, because the lockfile and workspace live there. If the platform only sees apps/web, it can't find packages/ui and the build fails with "Cannot find module".

Filtered builds with Turborepo

Instead of running build in every package, build only the target app and its dependencies:

turbo.json
{
  "$schema": "https://turbo.build/schema.json",
  "tasks": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": [".next/**", "!.next/cache/**", "dist/**"],
      "env": ["NEXT_PUBLIC_*"]
    }
  }
}
json10 lines

dependsOn: ["^build"] means the packages an app depends on are built before it. The env field tells Turborepo these variables affect the build output; forget it, and the cache may hand back a build with an old NEXT_PUBLIC_ value.

Don't build apps that didn't change

When only apps/web changed, the dashboard doesn't need a build. For each project, list the paths whose changes require a build: the app's own folder and the shared packages. Platforms usually support this with a "only build when these paths change" setting or an ignore-build command:

ignored build step
# Exit code 0 means "nothing changed, skip the build"
npx turbo-ignore web
bash2 lines

Next.js in a monorepo: standalone and file tracing

With output: "standalone", Next.js collects only the files it needs. In a monorepo you must tell it where the tracing root is, or files from shared packages get left out:

apps/web/next.config.mjs
import path from "node:path";

export default {
  output: "standalone",
  outputFileTracingRoot: path.join(__dirname, "../../"),
  transpilePackages: ["@workspace/ui", "@workspace/i18n"],
};
ts7 lines

From our own experience: once, after adding a library, the standalone image was built without @swc/helpers and pages errored in production while everything was fine on laptops. Always run the standalone output locally once with node server.js.

In short

One project per app; install from the root; filtered builds; and an exact list of the paths that require a build. With those four, a monorepo deploys as simply as a single-app repo.

Frequently asked questions

Join the discussion

No comments yet. Be the first to share your thoughts.