<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abhinandan</title>
    <description>The latest articles on DEV Community by Abhinandan (@abhinandan-verma).</description>
    <link>https://dev.to/abhinandan-verma</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1401235%2F8681f88a-7396-4ef6-889c-628f9575cdc0.png</url>
      <title>DEV Community: Abhinandan</title>
      <link>https://dev.to/abhinandan-verma</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abhinandan-verma"/>
    <language>en</language>
    <item>
      <title>Turborepo in Next.js: Guide for Faster &amp; Smarter Builds</title>
      <dc:creator>Abhinandan</dc:creator>
      <pubDate>Sun, 29 Sep 2024 09:52:37 +0000</pubDate>
      <link>https://dev.to/abhinandan-verma/turborepo-in-nextjs-guide-for-faster-smarter-builds-539f</link>
      <guid>https://dev.to/abhinandan-verma/turborepo-in-nextjs-guide-for-faster-smarter-builds-539f</guid>
      <description>&lt;p&gt;Hey developer! 👋 If you have been building Next.js projects, you've probably seen &lt;strong&gt;Turborepo&lt;/strong&gt; at some place, most probably GitHub repos. &lt;br&gt;
Don’t worry if you’re new to it—by the end of this post, you’ll know what Turborepo is, when to use it, and most importantly, how to set it up in your Next.js project. Let’s dive in!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo3zj3gkxuhnb4n16eyc3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo3zj3gkxuhnb4n16eyc3.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  1. What is Turborepo? 🚀
&lt;/h3&gt;

&lt;p&gt;So, Turborepo is a &lt;strong&gt;high-performance build system&lt;/strong&gt; designed for managing &lt;strong&gt;monorepos&lt;/strong&gt; in JavaScript and TypeScript projects. &lt;/p&gt;

&lt;p&gt;Now, before your head spins with jargon, let me break it down. A &lt;strong&gt;monorepo&lt;/strong&gt; means multiple related projects or apps are stored in a single repository, like if you have a web app and a mobile app that share the same code. Managing these can get messy, and that’s where Turborepo comes to the rescue you from the mess :)&lt;/p&gt;
&lt;h4&gt;
  
  
  In simple terms:
&lt;/h4&gt;

&lt;p&gt;Turborepo helps you manage and optimize how your project runs tasks like builds, tests, and linting, especially when you have a large codebase. It’s like a super-organized manager that makes sure no time is wasted.&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Why Should You Use Turborepo? ✨
&lt;/h3&gt;

&lt;p&gt;This is one of the important question that why should you use. So, if you’re working on a Next.js project, Turborepo can be a game-changer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;🚀 Super Fast Builds&lt;/strong&gt;: Turborepo caches the results of tasks (like builds) and reuses them if nothing has changed. This way, you only build what’s changed instead of building everything over and over again. Think of it as only reheating your leftovers instead of cooking a whole new meal each time!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;🔄 Parallel Task Execution&lt;/strong&gt;: Normally, tasks like testing or building are done one by one. But with Turborepo, tasks that don’t depend on each other run at the same time. It's like cooking multiple dishes on different burners instead of waiting for each one to finish.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;🛠 Incremental Builds&lt;/strong&gt;: Only the code that’s changed gets rebuilt. This reduces the waiting time, especially when working with large projects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;📦 Monorepo Magic&lt;/strong&gt;: If your project is a monorepo (e.g., multiple apps and shared components), Turborepo makes managing it much easier by optimizing tasks across all projects at once. No more running separate builds for each project.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  3. When Should You Use Turborepo? 🤔
&lt;/h3&gt;

&lt;p&gt;This is something that you should keep in mind while using Turborepo:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You have a &lt;strong&gt;large Next.js project&lt;/strong&gt; or monorepo with multiple apps and shared packages.&lt;/li&gt;
&lt;li&gt;Your build and test times are slowing you down, and you need faster results.&lt;/li&gt;
&lt;li&gt;You’re working with &lt;strong&gt;CI/CD pipelines&lt;/strong&gt; (Continuous Integration/Continuous Deployment) and want to optimize them.&lt;/li&gt;
&lt;li&gt;You have tasks that can be run &lt;strong&gt;in parallel&lt;/strong&gt;, like running lint checks, tests, and builds at the same time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In smaller projects, the benefits might not be immediately noticeable, but as your project scales, Turborepo becomes a lifesaver.&lt;/p&gt;
&lt;h3&gt;
  
  
  4. Setting Up Turborepo in a Next.js Project 🛠️
&lt;/h3&gt;

&lt;p&gt;Let’s get to the fun part: setting up Turborepo in a Next.js project! Don’t worry, it’s easier than you think.&lt;/p&gt;
&lt;h3&gt;
  
  
  I always believe that visualisation and real implementation make it easy to understand. So I created this GitHub Repo, just to structure of a Next.js + Turborepo project set-up
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Step 0: Set up Next.js Project
&lt;/h4&gt;

&lt;p&gt;You can go to the Next.js official site and get the command to start or simply copy-paste this command and wait for npm to get the project ready&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; npx create-next-app@latest &lt;span class="nt"&gt;--typescript&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 1: Install Turborepo
&lt;/h4&gt;

&lt;p&gt;First, let’s add Turborepo to your project. Open your terminal and run this command in your Next.js project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;turbo &lt;span class="nt"&gt;--save-dev&lt;/span&gt;

&lt;span class="c"&gt;# `npm install turbo --global` &lt;/span&gt;
&lt;span class="c"&gt;#  if you may need to install it &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you’re using &lt;strong&gt;yarn&lt;/strong&gt; or &lt;strong&gt;pnpm&lt;/strong&gt;, the command is pretty similar:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add turbo &lt;span class="nt"&gt;--dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2: Create a &lt;code&gt;turbo.json&lt;/code&gt; File
&lt;/h4&gt;

&lt;p&gt;Next, we need to set up Turborepo’s configuration. Create a file called &lt;code&gt;turbo.json&lt;/code&gt; in the root directory of your project. Here’s a simple configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"$schema"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://turbo.build/schema.json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"tasks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"dependsOn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"^build"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"outputs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;".next/**"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"!.next/cache/**"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"check-types"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"dependsOn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"^check-types"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"persistent"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"cache"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  What’s happening here? 🤔
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;build&lt;/code&gt;&lt;/strong&gt;: This task builds your project. The &lt;code&gt;dependsOn&lt;/code&gt; means that the build task depends on any other builds in the monorepo (if you have them). The &lt;code&gt;outputs&lt;/code&gt; tells Turborepo where to cache the results (in this case, the &lt;code&gt;.next&lt;/code&gt; and &lt;code&gt;dist&lt;/code&gt; folders).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;dev&lt;/code&gt;&lt;/strong&gt;: This is for your development server. Caching is disabled here since you’ll want to see real-time changes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;lint&lt;/code&gt;&lt;/strong&gt;: Linting (checking your code for errors) doesn’t generate any files, so &lt;code&gt;outputs&lt;/code&gt; is empty. If you have heard about ESLint &amp;amp; Prettier then it is related to that.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Step 3: Update Your &lt;code&gt;package.json&lt;/code&gt; Scripts
&lt;/h4&gt;

&lt;p&gt;Now, we need to update the scripts in your &lt;code&gt;package.json&lt;/code&gt; to use Turborepo. It’s simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"check-types"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"tsc --noEmit"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 4: Run the build and check-types with turbo
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  turbo build check-types
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;without changing code run this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  turbo check-types build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you will see something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; Tasks:    2 successful, 2 total
Cached:    2 cached, 2 total
  Time:    185ms &lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; FULL TURBO
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tells Turborepo to run your tasks using its optimized system instead of running them one by one.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 4: Run Turborepo 🚀
&lt;/h4&gt;

&lt;p&gt;You’re all set! Now, let’s run the development server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;turbo dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Behind the scenes, Turborepo will be caching, optimizing, and running tasks in parallel to give you faster results!&lt;/p&gt;

&lt;p&gt;Turborepo will handle running tasks across both apps efficiently. No more waiting forever for everything to build!&lt;/p&gt;

&lt;h3&gt;
  
  
  If you could not set up your project properly then you can refer to the &lt;a href="https://turbo.build/repo/docs/getting-started/installation" rel="noopener noreferrer"&gt;Official Docs&lt;/a&gt; here (Thanks to Vercel)
&lt;/h3&gt;




&lt;h3&gt;
  
  
  Wrapping It Up 🎁
&lt;/h3&gt;

&lt;p&gt;Turborepo is like the secret sauce to speeding up large Next.js projects. By caching results, running tasks in parallel, and only building what’s needed, it saves you tons of time. Plus, it’s super easy to set up, just like we did above.&lt;/p&gt;

&lt;p&gt;If your Next.js project is getting larger and build times are becoming an issue, Turborepo will be your best friend. Whether you’re managing multiple apps in a monorepo or just looking for faster builds, it’s the tool you didn’t know you needed—until now.&lt;/p&gt;

&lt;p&gt;I hope you got some value or at least a few points from this blogs&lt;/p&gt;




&lt;p&gt;Feel free to drop any questions below! I'm always happy to help 😊&lt;/p&gt;

&lt;p&gt;Thanks for Reading :)&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>turborepo</category>
      <category>javascript</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
