mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-15 02:14:44 +00:00
4.1 KiB
4.1 KiB
title | description |
---|---|
Kit Utilities | Nuxt Kit provides composable utilities to help interacting with Nuxt Hooks and Nuxt Builder. |
Kit Utilities
::ReadMore{link="/docs/guide/going-further/kit"} ::
Utilities
Modules
installModule
Install specified Nuxt module programmatically. This is helpful when your module depends on other modules. You can pass the module options as an object to inlineOptions
and they will be passed to the module's setup
function.
Type
async function installModule (moduleToInstall: string | NuxtModule, inlineOptions?: any, nuxt?: Nuxt)
Parameters
moduleToInstall
Type: string
| NuxtModule
Required: true
The module to install. Can be either a string with the module name or a module object itself.
inlineOptions
Type: any
Default: {}
An object with the module options to be passed to the module's setup
function.
nuxt
Type: Nuxt
Default: useNuxt()
Nuxt instance. If not provided, it will be retrieved from the context via useNuxt()
call.
Examples
import { defineNuxtModule, installModule } from '@nuxt/kit'
export default defineNuxtModule<ModuleOptions>({
async setup (options, nuxt) {
// will install @nuxtjs/fontaine with Roboto font and Impact fallback
await installModule('@nuxtjs/fontaine', {
// module configuration
fonts: [
{
family: 'Roboto',
fallbacks: ['Impact'],
fallbackName: 'fallback-a',
}
]
})
}
})
Programmatic Usage
loadNuxt(loadOptions)
buildNuxt(nuxt)
loadNuxtConfig(loadOptions)
Compatibility
checkNuxtCompatibility(constraints)
assertNuxtCompatibility(constraints)
hasNuxtCompatibility(constraints)
isNuxt2()
isNuxt3()
getNuxtVersion()
Auto-imports
addImports(imports)
addImportsDir(importDirs, { prepend? })
addImportsSources(importSources)
Components
addComponentsDir(dir)
addComponent(componentObject)
Context
useNuxt()
Pages
extendPages (callback: pages => void)
extendRouteRules (route: string, rule: NitroRouteConfig, options: ExtendRouteRulesOptions)
addRouteMiddleware (input: NuxtMiddleware | NuxtMiddleware[], options: AddRouteMiddlewareOptions)
Plugins
addPlugin(pluginOptions, { append? })
addPluginTemplate(pluginOptions, { append? })
Templates
addTemplate(templateOptions)
addTypeTemplate(templateOptions)
updateTemplates({ filter?: ResolvedNuxtTemplate => boolean })
Nitro
addServerHandler (handler)
addDevServerHandler (handler)
useNitro()
(only usable afterready
hook)addServerPlugin
addPrerenderRoutes
Resolving
resolvePath (path, resolveOptions?)
resolveAlias (path, aliases?)
findPath (paths, resolveOptions?)
createResolver (base)
Logging
useLogger(scope?)
Builder
extendWebpackConfig(callback, options?)
extendViteConfig(callback, options?)
addWebpackPlugin(webpackPlugin, options?)
addVitePlugin(vitePlugin, options?)