feat: detect target

Co-authored-by: Sebasiten Chopin <seb@nuxtjs.com>
This commit is contained in:
Pooya Parsa 2020-11-06 10:12:57 +01:00
parent 5fdc6ccfb6
commit ddccc9cb78
2 changed files with 14 additions and 2 deletions

View File

@ -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)
}

View File

@ -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')