mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-15 02:14:44 +00:00
feat(kit,schema): add addServerTemplate
utility (#29320)
This commit is contained in:
parent
8f89972de8
commit
e553032df6
@ -1,7 +1,7 @@
|
||||
import { existsSync, promises as fsp } from 'node:fs'
|
||||
import { basename, isAbsolute, join, parse, relative, resolve } from 'pathe'
|
||||
import hash from 'hash-sum'
|
||||
import type { Nuxt, NuxtTemplate, NuxtTypeTemplate, ResolvedNuxtTemplate, TSReference } from '@nuxt/schema'
|
||||
import type { Nuxt, NuxtServerTemplate, NuxtTemplate, NuxtTypeTemplate, ResolvedNuxtTemplate, TSReference } from '@nuxt/schema'
|
||||
import { withTrailingSlash } from 'ufo'
|
||||
import { defu } from 'defu'
|
||||
import type { TSConfig } from 'pkg-types'
|
||||
@ -32,6 +32,18 @@ export function addTemplate<T> (_template: NuxtTemplate<T> | string) {
|
||||
return template
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a virtual file that can be used within the Nuxt Nitro server build.
|
||||
*/
|
||||
export function addServerTemplate (template: NuxtServerTemplate) {
|
||||
const nuxt = useNuxt()
|
||||
|
||||
nuxt.options.nitro.virtual ||= {}
|
||||
nuxt.options.nitro.virtual[template.filename] = template.getContents
|
||||
|
||||
return template
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders given types using lodash template during build into the project buildDir
|
||||
* and register them as types.
|
||||
|
@ -6,7 +6,7 @@ export type { GenerateAppOptions, HookResult, ImportPresetWithDeprecation, NuxtA
|
||||
export type { ImportsOptions } from './types/imports'
|
||||
export type { AppHeadMetaObject, MetaObject, MetaObjectRaw, HeadAugmentations } from './types/head'
|
||||
export type { ModuleDefinition, ModuleMeta, ModuleOptions, ModuleSetupInstallResult, ModuleSetupReturn, NuxtModule, ResolvedModuleOptions } from './types/module'
|
||||
export type { Nuxt, NuxtApp, NuxtPlugin, NuxtPluginTemplate, NuxtTemplate, NuxtTypeTemplate, ResolvedNuxtTemplate } from './types/nuxt'
|
||||
export type { Nuxt, NuxtApp, NuxtPlugin, NuxtPluginTemplate, NuxtTemplate, NuxtTypeTemplate, NuxtServerTemplate, ResolvedNuxtTemplate } from './types/nuxt'
|
||||
export type { RouterConfig, RouterConfigSerializable, RouterOptions } from './types/router'
|
||||
|
||||
// Schema
|
||||
|
@ -42,6 +42,12 @@ export interface NuxtTemplate<Options = TemplateDefaultOptions> {
|
||||
write?: boolean
|
||||
}
|
||||
|
||||
export interface NuxtServerTemplate {
|
||||
/** The target filename once the template is copied into the Nuxt buildDir */
|
||||
filename: string
|
||||
getContents: () => string | Promise<string>
|
||||
}
|
||||
|
||||
export interface ResolvedNuxtTemplate<Options = TemplateDefaultOptions> extends NuxtTemplate<Options> {
|
||||
filename: string
|
||||
dst: string
|
||||
|
Loading…
Reference in New Issue
Block a user