Nuxt/packages/nitro/src/presets/vercel.ts

50 lines
1.1 KiB
TypeScript
Raw Normal View History

import { resolve } from 'pathe'
2020-11-20 00:16:31 +00:00
import { extendPreset, writeFile } from '../utils'
2021-01-22 19:55:59 +00:00
import { NitroPreset, NitroContext } from '../context'
2020-11-20 00:16:31 +00:00
import { node } from './node'
2021-01-22 19:55:59 +00:00
export const vercel: NitroPreset = extendPreset(node, {
entry: '{{ _internal.runtimeDir }}/entries/vercel',
2020-11-20 00:16:31 +00:00
output: {
dir: '{{ _nuxt.rootDir }}/.vercel_build_output',
serverDir: '{{ output.dir }}/functions/node/server',
publicDir: '{{ output.dir }}/static'
2020-11-20 00:16:31 +00:00
},
ignore: [
'vercel.json'
],
hooks: {
2021-01-22 19:55:59 +00:00
async 'nitro:compiled' (ctx: NitroContext) {
2020-11-20 00:16:31 +00:00
await writeRoutes(ctx)
}
}
})
2021-01-22 19:55:59 +00:00
async function writeRoutes ({ output }: NitroContext) {
2020-11-20 00:16:31 +00:00
const routes = [
{
src: '/sw.js',
headers: {
'cache-control': 'public, max-age=0, must-revalidate'
},
continue: true
},
{
src: '/_nuxt/(.*)',
headers: {
'cache-control': 'public,max-age=31536000,immutable'
},
continue: true
},
{
handle: 'filesystem'
},
{
src: '(.*)',
2020-11-20 01:38:06 +00:00
dest: '/.vercel/functions/server/index'
2020-11-20 00:16:31 +00:00
}
]
await writeFile(resolve(output.dir, 'config/routes.json'), JSON.stringify(routes, null, 2))
}