@sveltejs/adapter-vercel 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -75
- package/index.js +15 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,83 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
A SvelteKit adapter that creates a Vercel app.
|
|
4
4
|
|
|
5
|
-
If you're using [adapter-auto](
|
|
5
|
+
If you're using [adapter-auto](https://kit.svelte.dev/docs/adapter-auto), you don't need to install this unless you need to specify Vercel-specific options, since it's already included.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Docs
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Then in your `svelte.config.js`:
|
|
12
|
-
|
|
13
|
-
```js
|
|
14
|
-
import vercel from '@sveltejs/adapter-vercel';
|
|
15
|
-
|
|
16
|
-
export default {
|
|
17
|
-
kit: {
|
|
18
|
-
// default options are shown
|
|
19
|
-
adapter: vercel({
|
|
20
|
-
// if true, will deploy the app using edge functions
|
|
21
|
-
// (https://vercel.com/docs/concepts/functions/edge-functions)
|
|
22
|
-
// rather than serverless functions
|
|
23
|
-
edge: false,
|
|
24
|
-
|
|
25
|
-
// an array of dependencies that esbuild should treat
|
|
26
|
-
// as external when bundling functions
|
|
27
|
-
external: [],
|
|
28
|
-
|
|
29
|
-
// if true, will split your app into multiple functions
|
|
30
|
-
// instead of creating a single one for the entire app
|
|
31
|
-
split: false
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Environment Variables
|
|
38
|
-
|
|
39
|
-
Vercel makes a set of [deployment-specific environment variables](https://vercel.com/docs/concepts/projects/environment-variables#system-environment-variables) available. Like other environment variables, these are accessible from `$env/static/private` and `$env/dynamic/private` (sometimes — more on that later), and inaccessible from their public counterparts. To access one of these variables from the client:
|
|
40
|
-
|
|
41
|
-
```js
|
|
42
|
-
// +layout.server.js
|
|
43
|
-
import { VERCEL_COMMIT_REF } from '$env/static/private';
|
|
44
|
-
|
|
45
|
-
/** @type {import('./$types').LayoutServerLoad} */
|
|
46
|
-
export function load() {
|
|
47
|
-
return {
|
|
48
|
-
deploymentGitBranch: VERCEL_COMMIT_REF
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
```svelte
|
|
54
|
-
<!-- +layout.svelte -->
|
|
55
|
-
<script>
|
|
56
|
-
/** @type {import('./$types').LayoutServerData} */
|
|
57
|
-
export let data;
|
|
58
|
-
</script>
|
|
59
|
-
|
|
60
|
-
<p>This staging environment was deployed from {data.deploymentGitBranch}.</p>
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Since all of these variables are unchanged between build time and run time when building on Vercel, we recommend using `$env/static/private` — which will statically replace the variables, enabling optimisations like dead code elimination — rather than `$env/dynamic/private`. If you're deploying with `edge: true` you _must_ use `$env/static/private`, as `$env/dynamic/private` and `$env/dynamic/public` are not currently populated in edge functions on Vercel.
|
|
64
|
-
|
|
65
|
-
## Notes
|
|
66
|
-
|
|
67
|
-
### Vercel functions
|
|
68
|
-
|
|
69
|
-
Vercel functions contained in the `/api` directory at the project's root will _not_ be included in the deployment — these should be implemented as [server endpoints](https://kit.svelte.dev/docs/routing#server) in your SvelteKit app.
|
|
70
|
-
|
|
71
|
-
### Node version
|
|
72
|
-
|
|
73
|
-
Projects created before a certain date will default to using Node 14, while SvelteKit requires Node 16 or later. You can change that in your project settings:
|
|
74
|
-
|
|
75
|
-

|
|
76
|
-
|
|
77
|
-
## Troubleshooting
|
|
78
|
-
|
|
79
|
-
### Accessing the file system
|
|
80
|
-
|
|
81
|
-
You can't access the file system through methods like `fs.readFileSync` in Serverless/Edge environments. If you need to access files that way, do that during building the app through [prerendering](https://kit.svelte.dev/docs/page-options#prerender). If you have a blog for example and don't want to manage your content through a CMS, then you need to prerender the content (or prerender the endpoint from which you get it) and redeploy your blog everytime you add new content.
|
|
9
|
+
[Docs](https://kit.svelte.dev/docs/adapter-vercel)
|
|
82
10
|
|
|
83
11
|
## Changelog
|
|
84
12
|
|
package/index.js
CHANGED
|
@@ -193,16 +193,24 @@ function static_vercel_config(builder) {
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
for (const [path, page] of builder.prerendered.pages) {
|
|
196
|
-
|
|
196
|
+
let overrides_path = path.slice(1);
|
|
197
|
+
|
|
198
|
+
if (path !== '/') {
|
|
199
|
+
/** @type {string | undefined} */
|
|
200
|
+
let counterpart_route = path + '/';
|
|
201
|
+
|
|
202
|
+
if (path.endsWith('/')) {
|
|
203
|
+
counterpart_route = path.slice(0, -1);
|
|
204
|
+
overrides_path = path.slice(1, -1);
|
|
205
|
+
}
|
|
206
|
+
|
|
197
207
|
prerendered_redirects.push(
|
|
198
|
-
{ src: path, dest:
|
|
199
|
-
{ src:
|
|
208
|
+
{ src: path, dest: counterpart_route },
|
|
209
|
+
{ src: counterpart_route, status: 308, headers: { Location: path } }
|
|
200
210
|
);
|
|
201
|
-
|
|
202
|
-
overrides[page.file] = { path: path.slice(1, -1) };
|
|
203
|
-
} else {
|
|
204
|
-
overrides[page.file] = { path: path.slice(1) };
|
|
205
211
|
}
|
|
212
|
+
|
|
213
|
+
overrides[page.file] = { path: overrides_path };
|
|
206
214
|
}
|
|
207
215
|
|
|
208
216
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/adapter-vercel",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sveltejs/kit",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^16.18.6",
|
|
31
31
|
"typescript": "^4.9.4",
|
|
32
|
-
"@sveltejs/kit": "^1.
|
|
32
|
+
"@sveltejs/kit": "^1.3.4"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"@sveltejs/kit": "^1.0.0"
|