mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
feat: detect target
Co-authored-by: Sebasiten Chopin <seb@nuxtjs.com>
This commit is contained in:
parent
5fdc6ccfb6
commit
ddccc9cb78
@ -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)
|
||||
}
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user