feat(nuxt, kit): auto import defineNuxtConfig (#7497)

This commit is contained in:
pooya parsa 2022-09-14 13:10:10 +02:00 committed by GitHub
parent aaac46980c
commit ac0b3a63a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import { NuxtConfigSchema } from '@nuxt/schema'
export interface LoadNuxtConfigOptions extends LoadConfigOptions<NuxtConfig> {} export interface LoadNuxtConfigOptions extends LoadConfigOptions<NuxtConfig> {}
export async function loadNuxtConfig (opts: LoadNuxtConfigOptions): Promise<NuxtOptions> { export async function loadNuxtConfig (opts: LoadNuxtConfigOptions): Promise<NuxtOptions> {
(globalThis as any).defineNuxtConfig = (c: any) => c
const result = await loadConfig<NuxtConfig>({ const result = await loadConfig<NuxtConfig>({
name: 'nuxt', name: 'nuxt',
configFile: 'nuxt.config', configFile: 'nuxt.config',
@ -16,6 +17,7 @@ export async function loadNuxtConfig (opts: LoadNuxtConfigOptions): Promise<Nuxt
globalRc: true, globalRc: true,
...opts ...opts
}) })
delete (globalThis as any).defineNuxtConfig
const { configFile, layers = [], cwd } = result const { configFile, layers = [], cwd } = result
const nuxtConfig = result.config! const nuxtConfig = result.config!

View File

@ -234,10 +234,11 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise<Nuxt> {
return nuxt return nuxt
} }
/** @deprecated Use import { defineNuxtConfig } from 'nuxt/config' */ /** @deprecated `defineNuxtConfig` is auto imported. Remove import or alternatively use `import { defineNuxtConfig } from 'nuxt/config'`. */
export function defineNuxtConfig (config: NuxtConfig): NuxtConfig { export function defineNuxtConfig (config: NuxtConfig): NuxtConfig {
return config return config
} }
/** @deprecated Use import type { NuxtConfig } from 'nuxt/config' */ /** @deprecated Use `import type { NuxtConfig } from 'nuxt/config'`. */
export type { NuxtConfig } type _NuxtConfig = NuxtConfig
export type { _NuxtConfig as NuxtConfig }

View File

@ -1,2 +1,6 @@
/// <reference types="nitropack" /> /// <reference types="nitropack" />
export * from './dist/index' export * from './dist/index'
declare global {
const defineNuxtConfig: typeof import('nuxt/config')['defineNuxtConfig']
}

View File

@ -1,3 +1,3 @@
import { defineNuxtConfig } from 'nuxt/config' export default defineNuxtConfig({
export default defineNuxtConfig({}) })