From 2e2f6475b4f534d37310375b28c0057ced8a7320 Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Fri, 14 Mar 2025 12:30:54 +0100 Subject: [PATCH] docs: add mention of `addServerTemplate` to modules guide (#31369) --- docs/2.guide/3.going-further/3.modules.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/2.guide/3.going-further/3.modules.md b/docs/2.guide/3.going-further/3.modules.md index 856b2ea019..39e1f03af3 100644 --- a/docs/2.guide/3.going-further/3.modules.md +++ b/docs/2.guide/3.going-further/3.modules.md @@ -579,6 +579,22 @@ export default defineNuxtModule({ }) ``` +For the server, you should use the `addServerTemplate` utility instead. + +```ts +import { defineNuxtModule, addServerTemplate } from '@nuxt/kit' + +export default defineNuxtModule({ + setup (options, nuxt) { + // The file is added to Nitro's virtual file system and can be imported in the server code from 'my-server-module.mjs' + addServerTemplate({ + filename: 'my-server-module.mjs', + getContents: () => 'export const myServerModule = () => "hello world !"' + }) + } +}) +``` + #### Adding Type Declarations You might also want to add a type declaration to the user's project (for example, to augment a Nuxt interface