diff --git a/packages/nitro/src/config.ts b/packages/nitro/src/config.ts index 5fc80b3ee4..0b0ecc13dd 100644 --- a/packages/nitro/src/config.ts +++ b/packages/nitro/src/config.ts @@ -1,7 +1,7 @@ import { resolve } from 'path' import defu from 'defu' import { NuxtOptions } from '@nuxt/types' -import { tryImport, LIB_DIR, resolvePath } from './utils' +import { tryImport, LIB_DIR, resolvePath, detectTarget } from './utils' export type UnresolvedPath = string | ((SLSOptions) => string) @@ -57,7 +57,7 @@ export function getoptions (nuxtOptions: NuxtOptions): SLSOptions { targetDir: null } - let target = process.env.NUXT_SLS_TARGET || nuxtOptions.serverless.target || 'node' + let target = process.env.NUXT_SLS_TARGET || nuxtOptions.serverless.target || detectTarget() if (typeof target === 'function') { target = target(nuxtOptions) } diff --git a/packages/nitro/src/utils.ts b/packages/nitro/src/utils.ts index 584a670aa7..8fa7bacd55 100644 --- a/packages/nitro/src/utils.ts +++ b/packages/nitro/src/utils.ts @@ -42,5 +42,17 @@ export function resolvePath (options: SLSOptions, path: UnresolvedPath, resolveB return resolve(resolveBase, typeof path === 'string' ? path : path(options)) } +export function detectTarget () { + if (process.env.NETLIFY) { + return 'netlify' + } + + if (process.env.VERCEL_URL) { + return 'vercel' + } + + return 'node' +} + export const LIB_DIR = resolve(__dirname, '../lib') export const RUNTIME_DIR = resolve(LIB_DIR, 'runtime')