2020-11-20 00:16:31 +00:00
|
|
|
import { resolve } from 'upath'
|
|
|
|
import { extendPreset, writeFile } from '../utils'
|
|
|
|
import { SigmaPreset, SigmaContext } from '../context'
|
|
|
|
import { node } from './node'
|
|
|
|
|
|
|
|
export const vercel: SigmaPreset = extendPreset(node, {
|
|
|
|
output: {
|
|
|
|
dir: '{{ _nuxt.rootDir }}/.vercel_build_output',
|
2020-11-20 01:38:06 +00:00
|
|
|
serverDir: '{{ output.dir }}/functions/node/server/index.js',
|
2020-11-20 11:55:55 +00:00
|
|
|
publicDir: '{{ output.dir }}/static'
|
2020-11-20 00:16:31 +00:00
|
|
|
},
|
|
|
|
ignore: [
|
|
|
|
'vercel.json'
|
|
|
|
],
|
|
|
|
hooks: {
|
|
|
|
async 'sigma:compiled' (ctx: SigmaContext) {
|
|
|
|
await writeRoutes(ctx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
async function writeRoutes ({ output }: SigmaContext) {
|
|
|
|
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))
|
|
|
|
}
|