feat: support for `ServerlessFunctionConfig` and `EdgeFunctionConfig`
Adding support for :
-
memory,maxDurationandregionsfor Serverless Functions -
envVarsInUseandregionsfor Edge Functions
I tried to keep the types structure defined here: https://vercel.com/docs/build-output-api/v3 without breaking the current API.
Limitation: settings cannot be defined on a by function basis when using split = true, they are applied globaly.
Maybe there is a nicer API for this, but for now:
import vercel from '@sveltejs/adapter-vercel';
export default {
kit: {
adapter: vercel({
serverlessFunctionConfig: {
memory: 1024,
maxDuration: 10,
regions: ['cdg1']
},
})
}
};
and on the edge:
import vercel from '@sveltejs/adapter-vercel';
export default {
kit: {
adapter: vercel({
edge: true,
edgeFunctionConfig: {
envVarsInUse: ['ENV1'],
regions: ['cdg1']
}
})
}
};
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
- [ ] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
- [X] This message body should clearly illustrate what problems it solves.
- [ ] Ideally, include a test that fails without this PR but passes with it.
Tests
- [X] Run the tests with
pnpm testand lint the project withpnpm lintandpnpm check
Changesets
- [X] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running
pnpm changesetand following the prompts. All changesets should bepatchuntil SvelteKit 1.0
🦋 Changeset detected
Latest commit: 08842533c909b8046e2b9d1f0713e4517ab56cae
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
| Name | Type |
|---|---|
| @sveltejs/adapter-vercel | Minor |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
Thanks for the PR. Our current plan is to expose this sort of configuration within the routes themselves — #8383 — so we don't want to add adapter-level configuration for this stuff in the meantime (though there probably will be some default config for +server.js files).
Until we implement that — hopefully soon — you can achieve the same outcome by modifying the contents of .vercel/output. Slightly hacky, but totally within the scope of what the Build Output API is designed to facilitate!
That would be awesome @Rich-Harris! I'm currently maintaining a custom vercel adapter that fits my needs: I have taken the much simpler route of defining each route config in svelte.config.js in a vercel.json fashion:
const config = {
kit: {
adapter: vercel({
default: {
runtime: 'node',
regions: ['fra1'],
memory: 2048,
maxDuration: 30
},
functions: {
'/(landing)/.*': {
runtime: 'edge',
regions: ['cdg', 'fra']
},
'/api/.*': {
runtime: 'node', // not necessary
memory: 1024,
maxDuration: 45,
},
'/api/images/process': {
memory: 3008,
maxDuration: 60,
},
'/(app)/.*': {
maxDuration: 10,
}
}
})
}
};
A bit less hacky than modifying the contents of .vercel/output before each deployment 🙂