@@ -3,9 +3,7 @@ import { relative } from 'path';
3
3
import { fileURLToPath } from 'url' ;
4
4
import esbuild from 'esbuild' ;
5
5
6
- // By writing to .output, we opt in to the Vercel filesystem API:
7
- // https://vercel.com/docs/file-system-api
8
- const VERCEL_OUTPUT = '.output' ;
6
+ const dir = '.vercel_build_output' ;
9
7
10
8
/** @type {import('.') } **/
11
9
export default function ( ) {
@@ -15,17 +13,24 @@ export default function () {
15
13
async adapt ( builder ) {
16
14
const tmp = builder . getBuildDirectory ( 'vercel-tmp' ) ;
17
15
18
- builder . rimraf ( VERCEL_OUTPUT ) ;
16
+ builder . rimraf ( dir ) ;
19
17
builder . rimraf ( tmp ) ;
20
18
19
+ const files = fileURLToPath ( new URL ( './files' , import . meta. url ) ) ;
20
+
21
+ const dirs = {
22
+ static : `${ dir } /static` ,
23
+ lambda : `${ dir } /functions/node/render`
24
+ } ;
25
+
21
26
builder . log . minor ( 'Prerendering static pages...' ) ;
27
+
22
28
await builder . prerender ( {
23
- dest : `${ VERCEL_OUTPUT } /static`
29
+ dest : `${ dir } /static`
24
30
} ) ;
25
31
26
32
builder . log . minor ( 'Generating serverless function...' ) ;
27
33
28
- const files = fileURLToPath ( new URL ( './files' , import . meta. url ) ) ;
29
34
const relativePath = relative ( tmp , builder . getServerDirectory ( ) ) ;
30
35
31
36
builder . copy ( files , tmp , {
@@ -44,33 +49,33 @@ export default function () {
44
49
45
50
await esbuild . build ( {
46
51
entryPoints : [ `${ tmp } /entry.js` ] ,
47
- outfile : `${ VERCEL_OUTPUT } /server/pages/__render .js` ,
52
+ outfile : `${ dirs . lambda } /index .js` ,
48
53
target : 'node14' ,
49
54
bundle : true ,
50
55
platform : 'node'
51
56
} ) ;
52
57
53
- writeFileSync (
54
- `${ VERCEL_OUTPUT } /server/pages/package.json` ,
55
- JSON . stringify ( { type : 'commonjs' } )
56
- ) ;
58
+ writeFileSync ( `${ dirs . lambda } /package.json` , JSON . stringify ( { type : 'commonjs' } ) ) ;
57
59
58
60
builder . log . minor ( 'Copying assets...' ) ;
59
- builder . writeClient ( `${ VERCEL_OUTPUT } /static` ) ;
60
- builder . writeStatic ( `${ VERCEL_OUTPUT } /static` ) ;
61
61
62
- builder . log . minor ( 'Writing manifests...' ) ;
62
+ builder . writeStatic ( dirs . static ) ;
63
+ builder . writeClient ( dirs . static ) ;
64
+
65
+ builder . log . minor ( 'Writing routes...' ) ;
66
+
67
+ builder . mkdirp ( `${ dir } /config` ) ;
63
68
writeFileSync (
64
- `${ VERCEL_OUTPUT } / routes-manifest .json` ,
65
- JSON . stringify ( {
66
- version : 3 ,
67
- dynamicRoutes : [
68
- {
69
- page : '/__render' ,
70
- regex : '^ /.*'
71
- }
72
- ]
73
- } )
69
+ `${ dir } /config/ routes.json` ,
70
+ JSON . stringify ( [
71
+ {
72
+ handle : 'filesystem'
73
+ } ,
74
+ {
75
+ src : '/.*' ,
76
+ dest : '.vercel/functions/render'
77
+ }
78
+ ] )
74
79
) ;
75
80
}
76
81
} ;
0 commit comments