fix: @astrojs/vercel bug fixes (#3000)
* Fixed outDir * Updated server out * changeset * Renamed out to tmp
This commit is contained in:
parent
e8aaedcac8
commit
b5ed099eaf
2 changed files with 29 additions and 6 deletions
5
.changeset/sweet-ways-tan.md
Normal file
5
.changeset/sweet-ways-tan.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@astrojs/vercel': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixed build directory and clean-up
|
|
@ -23,7 +23,7 @@ export default function vercel(): AstroIntegration {
|
||||||
name: '@astrojs/vercel',
|
name: '@astrojs/vercel',
|
||||||
hooks: {
|
hooks: {
|
||||||
'astro:config:setup': ({ config }) => {
|
'astro:config:setup': ({ config }) => {
|
||||||
config.outDir = new URL('./.output/', config.outDir);
|
config.outDir = new URL('./.output/', config.root);
|
||||||
config.build.format = 'directory';
|
config.build.format = 'directory';
|
||||||
},
|
},
|
||||||
'astro:config:done': ({ setAdapter, config }) => {
|
'astro:config:done': ({ setAdapter, config }) => {
|
||||||
|
@ -33,21 +33,39 @@ export default function vercel(): AstroIntegration {
|
||||||
'astro:build:start': async ({ buildConfig }) => {
|
'astro:build:start': async ({ buildConfig }) => {
|
||||||
buildConfig.serverEntry = `${ENTRYFILE}.mjs`;
|
buildConfig.serverEntry = `${ENTRYFILE}.mjs`;
|
||||||
buildConfig.client = new URL('./static/', _config.outDir);
|
buildConfig.client = new URL('./static/', _config.outDir);
|
||||||
buildConfig.server = new URL('./server/pages/', _config.outDir);
|
buildConfig.server = new URL('./server/tmp/', _config.outDir);
|
||||||
},
|
},
|
||||||
'astro:build:done': async ({ dir, routes }) => {
|
'astro:build:done': async ({ dir, routes }) => {
|
||||||
const pagesDir = new URL('./server/pages/', dir);
|
/*
|
||||||
|
Why do we need two folders? Why don't we just generate all inside `server/pages/`?
|
||||||
|
When the app builds, it throws some metadata inside a `chunks/` folder.
|
||||||
|
|
||||||
|
./server/
|
||||||
|
pages/
|
||||||
|
__astro_entry.mjs
|
||||||
|
chunks/
|
||||||
|
(lots of js files)
|
||||||
|
|
||||||
|
Those chunks will count as serverless functions (which cost money), so we
|
||||||
|
need to bundle as much as possible in one file. Hence, the following code
|
||||||
|
*/
|
||||||
|
|
||||||
|
const tmpDir = new URL('./server/tmp/', dir);
|
||||||
|
const bundleDir = new URL('./server/pages/', dir);
|
||||||
|
|
||||||
|
await fs.mkdir(bundleDir, { recursive: true });
|
||||||
|
|
||||||
// Convert server entry to CommonJS
|
// Convert server entry to CommonJS
|
||||||
await esbuild.build({
|
await esbuild.build({
|
||||||
entryPoints: [fileURLToPath(new URL(`./${ENTRYFILE}.mjs`, pagesDir))],
|
entryPoints: [fileURLToPath(new URL(`./${ENTRYFILE}.mjs`, tmpDir))],
|
||||||
outfile: fileURLToPath(new URL(`./${ENTRYFILE}.js`, pagesDir)),
|
outfile: fileURLToPath(new URL(`./${ENTRYFILE}.js`, bundleDir)),
|
||||||
bundle: true,
|
bundle: true,
|
||||||
format: 'cjs',
|
format: 'cjs',
|
||||||
platform: 'node',
|
platform: 'node',
|
||||||
target: 'node14',
|
target: 'node14',
|
||||||
});
|
});
|
||||||
await fs.rm(new URL(`./${ENTRYFILE}.mjs`, pagesDir));
|
|
||||||
|
await fs.rm(tmpDir, { recursive: true });
|
||||||
|
|
||||||
// Routes Manifest
|
// Routes Manifest
|
||||||
// https://vercel.com/docs/file-system-api#configuration/routes
|
// https://vercel.com/docs/file-system-api#configuration/routes
|
||||||
|
|
Loading…
Reference in a new issue