@@ -23,7 +23,7 @@ export default function vercel(): AstroIntegration {
23
23
name : '@astrojs/vercel' ,
24
24
hooks : {
25
25
'astro:config:setup' : ( { config } ) => {
26
- config . outDir = new URL ( './.output/' , config . outDir ) ;
26
+ config . outDir = new URL ( './.output/' , config . root ) ;
27
27
config . build . format = 'directory' ;
28
28
} ,
29
29
'astro:config:done' : ( { setAdapter, config } ) => {
@@ -33,21 +33,39 @@ export default function vercel(): AstroIntegration {
33
33
'astro:build:start' : async ( { buildConfig } ) => {
34
34
buildConfig . serverEntry = `${ ENTRYFILE } .mjs` ;
35
35
buildConfig . client = new URL ( './static/' , _config . outDir ) ;
36
- buildConfig . server = new URL ( './server/pages /' , _config . outDir ) ;
36
+ buildConfig . server = new URL ( './server/tmp /' , _config . outDir ) ;
37
37
} ,
38
38
'astro:build:done' : async ( { dir, routes } ) => {
39
- const pagesDir = new URL ( './server/pages/' , dir ) ;
39
+ /*
40
+ Why do we need two folders? Why don't we just generate all inside `server/pages/`?
41
+ When the app builds, it throws some metadata inside a `chunks/` folder.
42
+
43
+ ./server/
44
+ pages/
45
+ __astro_entry.mjs
46
+ chunks/
47
+ (lots of js files)
48
+
49
+ Those chunks will count as serverless functions (which cost money), so we
50
+ need to bundle as much as possible in one file. Hence, the following code
51
+ */
52
+
53
+ const tmpDir = new URL ( './server/tmp/' , dir ) ;
54
+ const bundleDir = new URL ( './server/pages/' , dir ) ;
55
+
56
+ await fs . mkdir ( bundleDir , { recursive : true } ) ;
40
57
41
58
// Convert server entry to CommonJS
42
59
await esbuild . build ( {
43
- entryPoints : [ fileURLToPath ( new URL ( `./${ ENTRYFILE } .mjs` , pagesDir ) ) ] ,
44
- outfile : fileURLToPath ( new URL ( `./${ ENTRYFILE } .js` , pagesDir ) ) ,
60
+ entryPoints : [ fileURLToPath ( new URL ( `./${ ENTRYFILE } .mjs` , tmpDir ) ) ] ,
61
+ outfile : fileURLToPath ( new URL ( `./${ ENTRYFILE } .js` , bundleDir ) ) ,
45
62
bundle : true ,
46
63
format : 'cjs' ,
47
64
platform : 'node' ,
48
65
target : 'node14' ,
49
66
} ) ;
50
- await fs . rm ( new URL ( `./${ ENTRYFILE } .mjs` , pagesDir ) ) ;
67
+
68
+ await fs . rm ( tmpDir , { recursive : true } ) ;
51
69
52
70
// Routes Manifest
53
71
// https://vercel.com/docs/file-system-api#configuration/routes
0 commit comments