-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
--- | ||
|
||
# defineNuxt... helpers | ||
|
||
We added some helpers to optimize developer experience. | ||
|
||
## defineNuxtPlugin | ||
|
||
Create a Nuxt plugin with types with | ||
|
||
```ts | ||
import { defineNuxtPlugin } from 'nuxt-composition-api' | ||
|
||
export default defineNuxtPlugin((ctx) => { | ||
// do stuff | ||
}) | ||
``` | ||
|
||
## defineNuxtMiddleware | ||
|
||
Create a Nuxt plugin with types with | ||
|
||
```ts | ||
import { defineNuxtMiddleware } from 'nuxt-composition-api' | ||
|
||
export default defineNuxtMiddleware((ctx) => { | ||
// do stuff | ||
}) | ||
``` | ||
|
||
## defineNuxtModule | ||
|
||
Create a Nuxt plugin with types with | ||
|
||
```ts | ||
import { defineNuxtModule } from 'nuxt-composition-api' | ||
|
||
export default defineNuxtModule<{myOption: boolean}>((moduleOptions) => { | ||
// do stuff | ||
}) | ||
``` | ||
|
||
|
||
## defineNuxtServerMiddleware | ||
|
||
Create a Nuxt plugin with types with | ||
|
||
```ts | ||
import { defineNuxtServerMiddleware } from 'nuxt-composition-api' | ||
|
||
export default defineNuxtServerMiddleware((req, res, next) => { | ||
// do stuff | ||
}) | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Middleware, Plugin, Module, ServerMiddleware } from '@nuxt/types' | ||
|
||
export const defineNuxtPlugin = (plugin: Plugin) => plugin | ||
export const defineNuxtMiddleware = (middleware: Middleware) => middleware | ||
export const defineNuxtModule = <T extends Record<string, unknown>>( | ||
module: Module<T> | ||
) => module | ||
export const defineNuxtServerMiddleware = ( | ||
serverMiddleware: ServerMiddleware | ||
) => serverMiddleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { | ||
defineNuxtPlugin, | ||
defineNuxtMiddleware, | ||
defineNuxtModule, | ||
defineNuxtServerMiddleware, | ||
} from '../..' | ||
import { expectType } from 'tsd' | ||
|
||
defineNuxtPlugin((context, inject) => { | ||
const hello = (msg: string) => console.log(`Hello ${msg}!`) | ||
|
||
expectType<boolean>(context.isClient) | ||
|
||
inject('hello', hello) | ||
}) | ||
|
||
defineNuxtModule<{ | ||
option: string | ||
}>(function (options) { | ||
// expectType<string>(this.options.rootDir) | ||
|
||
this.addPlugin('filename') | ||
|
||
expectType<string>(options.option) | ||
}) | ||
|
||
defineNuxtMiddleware(({ store, redirect }) => { | ||
if (!store.state.authenticated) { | ||
return redirect('/login') | ||
} | ||
}) | ||
|
||
defineNuxtServerMiddleware((req, res, next) => { | ||
expectType<string | undefined>(req.url) | ||
|
||
next() | ||
}) |
8a9885e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: