I have a basic api made using Express and Vercel Serverless Functions.
I deployed my project on vercel and got everything working perfect.
This is the vercel.json I used:
{
"version": 2,
"builds": [
{
"src": "api/batteries.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/api/batteries",
"dest": "api/batteries.js"
}
]
}
Going through the Vercel docs, I found this:
We recommend against using this property. To customize Serverless Functions, please use the functions property instead.
We recommend using cleanUrls, trailingSlash, redirects, rewrites, and/or headers instead.
When i used the recommended Functions and Rewrites property instead of the legacy ones, files at the root of my project (test.js and pnpm-lock.yaml) started to being served as static assets.
This is the vercel.json configuration I’m having issues with:
{
"functions": {
"api/batteries.js": {
"memory": 128,
"maxDuration": 10
}
},
"rewrites": [
{
"source": "/api/batteries",
"destination": "/api/batteries.js"
}
]
}
My project structure:
- api/batteries.js
- .gitignore
- pnpm-lock.yaml
- package.json
- test.js
- vercel.json
Is there any property I might have missed to explicitly exclude files from the build output?
As the builds property was handling it automatically for me:
When at least one
builds
item is specified, only the outputs of the build processes will be included in the resulting deployment as a security precaution. This is why we need to allowlist static files explicitly with@vercel/static
.
Additional Info:
- I can’t use .vercelignore as doing so will unwantedly increase the build time cuz the package manager will have to resolve all the deps every time build is triggered.
- excludeFiles will obviously not work as it does not interfere with the build step or output. It will exclude the lockfile from the Serverless Function.