mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
39 lines
1.2 KiB
Markdown
39 lines
1.2 KiB
Markdown
|
# Nuxt Kit
|
||
|
|
||
|
> Nuxt Kit provides composable utilities to make interacting with [Nuxt Hooks](/api/advanced/hooks) and [Nuxt Builder Core](/guide/going-further/internals#the-nuxt-interface) and developing [Nuxt Modules](/guide/going-further/modules) super easy!
|
||
|
|
||
|
## Usage
|
||
|
|
||
|
### Install dependency
|
||
|
|
||
|
You can install the latest nuxt kit by adding it to `dependencies` of `package.json`. However, please consider always explicitly installing the `@nuxt/kit` package even if it is already installed by nuxt.
|
||
|
|
||
|
```json [package.json]
|
||
|
{
|
||
|
"dependencies": {
|
||
|
"@nuxt/kit": "npm:@nuxt/kit-edge@latest"
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
|
### Import kit utilities
|
||
|
|
||
|
```js [test.mjs]
|
||
|
import { useNuxt } from '@nuxt/kit'
|
||
|
```
|
||
|
|
||
|
::alert{type="warning"}
|
||
|
Nuxt kit utilities are only available for modules and not meant to be imported in runtime (components, vue composables, pages, plugins, or server routes)
|
||
|
::
|
||
|
|
||
|
Nuxt kit, is an [esm-only package](/guide/going-further/esm) meaning you **cannot** `require('@nuxt/kit')`. As a workaround, we can use dynamic import to use it in the CommonJS context:
|
||
|
|
||
|
```js [test.cjs]
|
||
|
// This does NOT work!
|
||
|
// const kit = require('@nuxt/kit')
|
||
|
async function main() {
|
||
|
const kit = await import('@nuxt/kit')
|
||
|
}
|
||
|
main()
|
||
|
```
|