Alfonso's Website
2 min read time

How to ignore Vercel build step for certain folders and files

When using Vercel for monolithic projects that may contain files that are not part of the frontend, you may encounter a situation where every time you modify something that is not necessarily part of the frontend, Vercel triggers a new deployment that rebuilds the site automatically.

In those cases, you may need to ensure that the build process is only triggered when necessary.

Luckily Vercel has an Ignored Build Step setting that allows you to disable the build step for specific scenarios, the problem is that the examples explain how you can trigger the build step in a particular folder but not how to ignore the folder. (For example, let's say that you don't want to build the entire site if you only changed the /api folder)

To do that, follow these steps:

  1. Go to project settings:

  1. Select the Git Tab:

  1. Go to the Ignored Build Step

  1. Add the following code:
# Change `./api` for the path of the folder you want to ignore
git diff HEAD^ HEAD --quiet ':!./api'

You may also want to ignore certain file types. For those cases, modify the code as follows:

# Replace `'php'` with the file extensions you want to ignore.
git diff HEAD^ HEAD --quiet ':!*.php'

You can also add multiple file types:

git diff HEAD^ HEAD --quiet ':!*.php' ':!*.png'

Or a single file

git diff HEAD^ HEAD --quiet ':!config.ts'