Workspace-specific turbo config

This lesson preview is part of the Bundling and Automation in Monorepos course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

This video is available to students only
Unlock This Course

Get unlimited access to Bundling and Automation in Monorepos, plus 90+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course Bundling and Automation in Monorepos
  • [00:00 - 00:22] There is one thing I want to improve in our turbo setup. So right now we have our build outputs set in a way that captures everything in the monorepo. But we ended up having one thing that captures four workspaces in the monorepo, and another one that's only for Next.js.

    [00:23 - 00:59] What we could do instead is create a special turbo.json file for our Next.js application only and have its own setup in there, rather than trying to put everything in the root turbo.json file. So let's do that. I'm going to open "apps/frontend-nextjs/turbo.json" and I'm again going to pull the schema and add "extends".

    [01:00 - 01:26] The only valid value for "extends" is this double slash which means extend from the root. And then I'm going to copy over my build task. Like this. And our outputs are the ".next" folder with the exclusion of the ".next/cache" folder.

    [01:27 - 02:14] And here we can now change our outputs on the general turbo.json to just be the "dist" folder. With this change I can do "pnpm turbo build". It's going to rebuild everything because we changed turbo.json which changes our route dependency. And if we rerun it now, it runs fast and I can go to our apps/frontend-nextjs and "tree -L 1 .next". So this is what the .next folder looks like.

    [02:15 - 02:27] I'm going to delete the whole dot next folder, and I'm then going to run "pnpm turbo build" in here. It then should recreate the .next folder and it did.

    [02:28 - 02:51] So we specified a different output setting for our task only for this particular workspace and it is correctly executed. If I open my turbo.json again here in the Next.JS app, this is a way to be very explicit with your dependencies, outputs or inputs to a task.

    [02:52 - 03:02] So this is all that was necessary to have our custom config. Let's add our changes and let's look at what we did.

    [03:03 - 03:26] We changed our root turbo.json to be simpler, and we pushed the Next.JS specific things into the apps/frontend-nextjs/turbo.json definition. And I'm going to commit this as "Use workspace specific turbo build task definition for Next.JS". This is everything and I will see you in the next lesson.