Advanced Configuration
Learn how to add utility files to the /api directory, and bundle Vercel Functions.For an advanced configuration, you can create a vercel.json
file to use Runtimes and other customizations. To view more about the properties you can customize, see the Configuring Functions and Project config with vercel.json.
If your use case requires that you work asynchronously with the results of a function invocation, you may need to consider a queuing, pooling, or streaming approach because of how functions are created on Vercel.
Sometimes, you need to place extra code files, such as utils.js
or my-types.d.ts
, inside the /api
folder. To avoid turning these files into functions, Vercel ignores files with the following characters:
- Files that start with an underscore,
_
- Files that start with
.
- Files that end with
.d.ts
If your file uses any of the above, it will not be turned into a function.
In order to optimize resources, Vercel uses a process to bundle as many routes as possible into a single Vercel Function.
To provide more control over the bundling process, you can use the functions
property in your vercel.json
file to define the configuration for a route. If a configuration is present, Vercel will bundle functions based on the configuration first. Vercel will then bundle together the remaining routes, optimizing for how many functions are created.
This bundling process is currently only enabled for Next.js, but it will be enabled in other scenarios in the future.
In the following example, app/api/hello/route.ts
will be bundled separately from app/api/another/route.ts
since each has a different configuration:
{
"functions": {
"app/api/hello/route.ts": {
"memory": 3009,
"maxDuration": 60
},
"app/api/another/route.ts": {
"memory": 1024,
"maxDuration": 30
}
}
}
Was this helpful?