2020-11-20 00:16:31 +00:00
|
|
|
import { resolve } from 'upath'
|
|
|
|
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, {
|
2020-11-20 12:49:21 +00:00
|
|
|
entry: '{{ _internal.runtimeDir }}/entries/vercel',
|
2020-11-20 00:16:31 +00:00
|
|
|
output: {
|
|
|
|
dir: '{{ _nuxt.rootDir }}/.vercel_build_output',
|
2020-11-20 12:04:16 +00:00
|
|
|
serverDir: '{{ output.dir }}/functions/node/server',
|
2020-11-20 11:55:55 +00:00
|
|
|
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))
|
|
|
|
}
|