mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 09:02:03 +00:00
feat(nitro): support netlify zero-config deployments (#175)
This commit is contained in:
parent
8337d59854
commit
9750009cc5
@ -1,11 +1,31 @@
|
|||||||
|
import { join } from 'upath'
|
||||||
|
import { existsSync, readFile, writeFile } from 'fs-extra'
|
||||||
|
import consola from 'consola'
|
||||||
import { extendPreset } from '../utils'
|
import { extendPreset } from '../utils'
|
||||||
import { NitroPreset } from '../context'
|
import { NitroContext, NitroPreset } from '../context'
|
||||||
import { lambda } from './lambda'
|
import { lambda } from './lambda'
|
||||||
|
|
||||||
export const netlify: NitroPreset = extendPreset(lambda, {
|
export const netlify: NitroPreset = extendPreset(lambda, {
|
||||||
output: {
|
output: {
|
||||||
|
dir: '{{ _nuxt.rootDir }}/netlify/functions',
|
||||||
publicDir: '{{ _nuxt.rootDir }}/dist'
|
publicDir: '{{ _nuxt.rootDir }}/dist'
|
||||||
},
|
},
|
||||||
|
hooks: {
|
||||||
|
async 'nitro:compiled' (ctx: NitroContext) {
|
||||||
|
const redirectsPath = join(ctx._nuxt.rootDir, '_redirects')
|
||||||
|
let contents = '/* /.netlify/functions/server 200'
|
||||||
|
if (existsSync(redirectsPath)) {
|
||||||
|
const currentRedirects = await readFile(redirectsPath, 'utf-8')
|
||||||
|
if (currentRedirects.match(/^\/\* /m)) {
|
||||||
|
consola.info('Not adding Nitro fallback to `_redirects` (as an existing fallback was found).')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
consola.info('Adding Nitro fallback to `_redirects` to handle all unmatched routes.')
|
||||||
|
contents = currentRedirects + '\n' + contents
|
||||||
|
}
|
||||||
|
await writeFile(redirectsPath, contents)
|
||||||
|
}
|
||||||
|
},
|
||||||
ignore: [
|
ignore: [
|
||||||
'netlify.toml',
|
'netlify.toml',
|
||||||
'_redirects'
|
'_redirects'
|
||||||
|
Loading…
Reference in New Issue
Block a user