Prevent Uploading Source Paths with .vercelignore on Vercel
Use a .vercelignore file to prevent the uploading of source paths when deploying with Vercel.
Vercel supports configuration required to ignore source files and paths within your project. With a .vercelignore
file in your project directory, a source path can be prevented from being uploaded to Vercel.
File Syntax
The syntax of a .vercelignore
file matches that of the popular .gitignore
file used in ignoring files when uploading to a Git repository.
An example of a .vercelignore
file that prevents an /image
directory and /private.html
file within a project from being uploaded to Vercel would look like this:
image private.html
An example .vercelignore
file.
Allowlist
A typical .vercelignore
file assumes all files are allowed and each entry is a pattern to ignore. Alternatively, you may chose to ignore all files and each entry is a pattern to allow.
The first step is to add a wildcard /*
as the first line in .vercelignore
. This will ensure all directories and files in the project root are ignored. The following lines must start with a !
to invert the ignore action and ensure the directory or file is allowed.
# Ignore everything (folders and files) on root only /* !api !vercel.json !*.html
An example .vercelignore
file using the "allowlist" pattern.
Uploaded Files
Aside from the default exclusions, all files within your project are uploaded to Vercel if no source path is specified to be excluded in a .vercelignore
configuration file.
Worthy of note is that not all uploaded files are served on Vercel. So, what files are served?
Served Files
If Vercel is required to build your project, the non-targeted files are prevented from being deployed and served on Vercel.
The use of a .vercelignore
configuration file allows you to keep private files safe and also makes your deployment faster by uploading only the essential files.