DEV Community

Gaëtan Redin
Gaëtan Redin

Posted on • Originally published at Medium on

Nx + Pnpm + Netlify

How to deploy an application from a mono repo

Context

Hey, you know when you want to develop an app or a website, there is a time to deploy it.

For several months, I only work with Nx workspace. No need, to explain here all the benefits Nx can bring you but I invit you to visit the web site. In short, it allows you to handle several apps and libs inside the same workspace. You can develop Angular, React and Node projects still in the same workspace.

Last week, I decided to use pnpm instead of npm. I find it so faster. There is no word to define the pleasure to make an install with it.

Today, I want to deploy one of my application thanks to Netlify. I heard good things about it.

But, netlify does not work natively with pnpm and there some tricks to know for mono repos. I will try to help you to do this. To accomplish this, I suppose you already have a mono repo with an app to deploy and you have create an account on netlify.

The steps

I guess, you have an architecture as following:

- apps
    - my-first-app
    - my-second-app
    - ...
- libs
Enter fullscreen mode Exit fullscreen mode

Now, I suppose you want to deploy my-first-app.

First, you need to add a script into your package.

// package.json
"scripts": {
    "build:my-first-app": "nx build my-first-app --outputPath=apps/my-first-app/dist",
}
Enter fullscreen mode Exit fullscreen mode

This will corresponds to the standard dist folder for netlify. This needs to be merged on your main branch (or the branch you decide to deploy).

So go to netlify web site and go to the deploy tab link:

Go to deploy settings:

Go to Build settings and click on Edit settings:

Fill with the information like below:

Put this in the Build command field:

pnpm run build:my-first-app || ( npm install pnpm && pnpm run build:my-first-app )
Enter fullscreen mode Exit fullscreen mode

Click on save. Et voilà (I’m french I can say that too). Trigger a new deploy and it will be ok.

I hope this could help someone.

Thanks for reading.

Learn more

Top comments (0)