docs: add mention of addServerTemplate to modules guide (#31369)

This commit is contained in:
Guillaume Chau 2025-03-14 12:30:54 +01:00 committed by Daniel Roe
parent d7ee76bbb8
commit cc5be870d7
No known key found for this signature in database
GPG Key ID: CBC814C393D93268

View File

@ -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