mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix(nuxt): augment nitro config within server context as well (#21724)
This commit is contained in:
parent
1cd48cbef9
commit
5b8370414a
@ -1,7 +1,7 @@
|
|||||||
import { join, normalize, relative, resolve } from 'pathe'
|
import { join, normalize, relative, resolve } from 'pathe'
|
||||||
import { createDebugger, createHooks } from 'hookable'
|
import { createDebugger, createHooks } from 'hookable'
|
||||||
import type { LoadNuxtOptions } from '@nuxt/kit'
|
import type { LoadNuxtOptions } from '@nuxt/kit'
|
||||||
import { addBuildPlugin, addComponent, addPlugin, addTemplate, addVitePlugin, addWebpackPlugin, installModule, loadNuxtConfig, logger, nuxtCtx, resolveAlias, resolveFiles, resolvePath, tryResolveModule } from '@nuxt/kit'
|
import { addBuildPlugin, addComponent, addPlugin, addVitePlugin, addWebpackPlugin, installModule, loadNuxtConfig, logger, nuxtCtx, resolveAlias, resolveFiles, resolvePath, tryResolveModule } from '@nuxt/kit'
|
||||||
import type { Nuxt, NuxtHooks, NuxtOptions } from 'nuxt/schema'
|
import type { Nuxt, NuxtHooks, NuxtOptions } from 'nuxt/schema'
|
||||||
|
|
||||||
import escapeRE from 'escape-string-regexp'
|
import escapeRE from 'escape-string-regexp'
|
||||||
@ -154,14 +154,6 @@ async function initNuxt (nuxt: Nuxt) {
|
|||||||
// Transpile #app if it is imported directly from subpath export
|
// Transpile #app if it is imported directly from subpath export
|
||||||
nuxt.options.build.transpile.push('nuxt/app')
|
nuxt.options.build.transpile.push('nuxt/app')
|
||||||
|
|
||||||
// This is currently a placeholder for future augmentations that need to be applied in Nitro context
|
|
||||||
addTemplate({
|
|
||||||
filename: 'types/nitro-nuxt.d.ts',
|
|
||||||
getContents: () => {
|
|
||||||
return 'export {}'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Transpile layers within node_modules
|
// Transpile layers within node_modules
|
||||||
nuxt.options.build.transpile.push(
|
nuxt.options.build.transpile.push(
|
||||||
...nuxt.options._layers.filter(i => i.cwd.includes('node_modules')).map(i => i.cwd as string)
|
...nuxt.options._layers.filter(i => i.cwd.includes('node_modules')).map(i => i.cwd as string)
|
||||||
|
@ -199,6 +199,39 @@ export const middlewareTemplate: NuxtTemplate<TemplateContext> = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const nitroSchemaTemplate: NuxtTemplate = {
|
||||||
|
filename: 'types/nitro-nuxt.d.ts',
|
||||||
|
getContents: () => {
|
||||||
|
return /* typescript */`
|
||||||
|
/// <reference path="./schema.d.ts" />
|
||||||
|
|
||||||
|
import type { RuntimeConfig } from 'nuxt/schema'
|
||||||
|
import type { H3Event } from 'h3'
|
||||||
|
import type { NuxtIslandContext, NuxtIslandResponse, NuxtRenderHTMLContext } from 'nuxt/dist/core/runtime/nitro/renderer'
|
||||||
|
|
||||||
|
declare module 'nitropack' {
|
||||||
|
interface NitroRuntimeConfigApp {
|
||||||
|
buildAssetsDir: string
|
||||||
|
cdnURL: string
|
||||||
|
}
|
||||||
|
interface NitroRuntimeConfig extends RuntimeConfig {}
|
||||||
|
interface NitroRouteConfig {
|
||||||
|
ssr?: boolean
|
||||||
|
experimentalNoScripts?: boolean
|
||||||
|
}
|
||||||
|
interface NitroRouteRules {
|
||||||
|
ssr?: boolean
|
||||||
|
experimentalNoScripts?: boolean
|
||||||
|
}
|
||||||
|
interface NitroRuntimeHooks {
|
||||||
|
'render:html': (htmlContext: NuxtRenderHTMLContext, context: { event: H3Event }) => void | Promise<void>
|
||||||
|
'render:island': (islandResponse: NuxtIslandResponse, context: { event: H3Event, islandContext: NuxtIslandContext }) => void | Promise<void>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const clientConfigTemplate: NuxtTemplate = {
|
export const clientConfigTemplate: NuxtTemplate = {
|
||||||
filename: 'nitro.client.mjs',
|
filename: 'nitro.client.mjs',
|
||||||
getContents: () => `
|
getContents: () => `
|
||||||
|
2
packages/nuxt/types.d.ts
vendored
2
packages/nuxt/types.d.ts
vendored
@ -2,6 +2,7 @@
|
|||||||
export * from './dist/index'
|
export * from './dist/index'
|
||||||
|
|
||||||
import type { SchemaDefinition, RuntimeConfig } from 'nuxt/schema'
|
import type { SchemaDefinition, RuntimeConfig } from 'nuxt/schema'
|
||||||
|
import type { H3Event } from 'h3'
|
||||||
import type { NuxtIslandContext, NuxtIslandResponse, NuxtRenderHTMLContext } from './dist/core/runtime/nitro/renderer'
|
import type { NuxtIslandContext, NuxtIslandResponse, NuxtRenderHTMLContext } from './dist/core/runtime/nitro/renderer'
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
@ -9,6 +10,7 @@ declare global {
|
|||||||
const defineNuxtSchema: (schema: SchemaDefinition) => SchemaDefinition
|
const defineNuxtSchema: (schema: SchemaDefinition) => SchemaDefinition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note: Keep in sync with packages/nuxt/src/core/templates.ts
|
||||||
declare module 'nitropack' {
|
declare module 'nitropack' {
|
||||||
interface NitroRuntimeConfigApp {
|
interface NitroRuntimeConfigApp {
|
||||||
buildAssetsDir: string
|
buildAssetsDir: string
|
||||||
|
Loading…
Reference in New Issue
Block a user