Skip to content

Commit

Permalink
feat: add defineNuxtConfig helper
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Feb 9, 2021
1 parent 931b45f commit 6484e97
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
---
title: Definition helpers
description: '@nuxtjs/composition-api provides a way to use the Vue 3 Composition API with Nuxt-specific features.'
category: Helpers
title: defineNuxt*
description: 'You can get automatic type-hinting for Nuxt configuration, plugins, middleware, modules and serverMiddleware.'
category: Typings
position: 10
version: 0.192

---

There are some helpers to optimize developer experience when creating Nuxt plugins, middleware, server middleware and modules.

These helpers simply return the function passed into them, adding the correct typings.
These helpers simply return the function or object passed into them, adding the correct typings.

## defineNuxtConfig

Create your `nuxt.config.js` with types with:

```ts
import { defineNuxtConfig } from '@nuxtjs/composition-api'

export default defineNuxtConfig({
// your nuxt config
})
```

## defineNuxtPlugin

Expand Down Expand Up @@ -57,4 +71,3 @@ export default defineNuxtServerMiddleware((req, res, next) => {
// do stuff
})
```

9 changes: 8 additions & 1 deletion src/defineHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Middleware, Plugin, Module, ServerMiddleware } from '@nuxt/types'
import {
Middleware,
Plugin,
Module,
ServerMiddleware,
NuxtConfig,
} from '@nuxt/types'

export const defineNuxtPlugin = (plugin: Plugin) => plugin
export const defineNuxtMiddleware = (middleware: Middleware) => middleware
Expand All @@ -8,3 +14,4 @@ export const defineNuxtModule = <T extends Record<string, unknown>>(
export const defineNuxtServerMiddleware = (
serverMiddleware: ServerMiddleware
) => serverMiddleware
export const defineNuxtConfig = (config: NuxtConfig) => config

0 comments on commit 6484e97

Please sign in to comment.