• Discover
  • Collections
  • Board
  • Create
  • Profile
  • Settings
Paths

Migrating Next.js Applications to Turborepo

Migrating Next.js Applications to Turborepo

2 min read

Overview

This lesson details the process of migrating an existing, standalone Next.js application into your newly created Turborepo monorepo structure. We'll cover moving files, updating configurations, and integrating it as a workspace.

Key Points

  • Move Next.js App: Physically relocate your existing Next.js project directory into the apps/ folder of your monorepo (e.g., my-monorepo/apps/my-next-app).

  • Update package.json: Adjust the name field in the Next.js app's package.json to be unique within the monorepo. Ensure its dependencies are properly listed.

  • Configure tsconfig.json: Update the tsconfig.json within your Next.js app to correctly resolve paths to shared packages. You might use baseUrl and paths for this.

  • Adjust Build Scripts in turbo.json: Add or modify the build, dev, lint, and test scripts for your Next.js app within the root turbo.json to leverage Turborepo's task runner.

  • Install Dependencies: Run pnpm install (or your chosen package manager's equivalent) from the monorepo root to link all workspace dependencies.

Quick Example

Here's how you might define a build script for a Next.js app named web in turbo.json:

json
{ "pipeline": { "build": { "dependsOn": ```json ["^build"]

, "outputs":

json
[".next/**", "!**/.next/cache/**"]
},
"web#build": {
  "dependsOn": 
json
["^build"]

, "outputs":

json
[".next/**", "!**/.next/cache/**"]
}

}



}


In `apps/web/package.json` you would have a `build` script like `next build`.

## Summary

Migrating a Next.js app to a Turborepo involves relocating files, updating individual `package.json` and `tsconfig.json` files, and integrating its build process into the monorepo's `turbo.json`. This ensures the app can be built and developed efficiently within the new structure.
End of lesson
👏Well done!
Previous Lesson
Initializing a Turborepo Project
Next Lesson
Integrating Shared UI Components and Utilities

Course Content

0% Complete0/12 Lessons

Introduction to Monorepos and Turborepo

Core Concepts of Turborepo

Planning Your Monorepo Migration

Quiz

Initializing a Turborepo Project

Migrating Next.js Applications to Turborepo

Integrating Shared UI Components and Utilities

Quiz

Course Content

0% Complete0/12 Lessons

Introduction to Monorepos and Turborepo

Core Concepts of Turborepo

Planning Your Monorepo Migration

Quiz

Initializing a Turborepo Project

Migrating Next.js Applications to Turborepo

Integrating Shared UI Components and Utilities

Quiz