diff --git a/packages/kit/src/nitro.ts b/packages/kit/src/nitro.ts index ce88422c5f1..ebdf58d4e40 100644 --- a/packages/kit/src/nitro.ts +++ b/packages/kit/src/nitro.ts @@ -1,4 +1,5 @@ import type { NitroEventHandler, NitroDevEventHandler, Nitro } from 'nitropack' +import { normalize } from 'pathe' import { useNuxt } from './context' /** @@ -30,6 +31,15 @@ export function addDevServerHandler (handler: NitroDevEventHandler) { useNuxt().options.devServerHandlers.push(handler) } +/** + * Adds a Nitro plugin + */ +export function addServerPlugin (plugin: string) { + const nuxt = useNuxt() + nuxt.options.nitro.plugins = nuxt.options.nitro.plugins || [] + nuxt.options.nitro.plugins.push(normalize(plugin)) +} + /** * Access to the Nitro instance *