Auto Imports

Nitro is using unjs/unimport to auto import utilities when used with full tree-shaking support.

Available Auto Imports

  • defineCachedFunction(fn, options) / cachedFunction(fn, options)
  • defineCachedEventHandler(handler, options) / cachedEventHandler(handler, options)
  • defineRenderHandler(handler)
  • useRuntimeConfig(event?)
  • useAppConfig(event?)
  • useStorage(base?)
  • useNitroApp()
  • defineNitroPlugin(plugin)
  • nitroPlugin(plugin)
  • getRouteRules(event)

Check the source code for list of available auto imports.

With TypeScript enabled, you can easily see them as global utilities in your IDE.

The types are auto generated for global auto-imports when running the prepare or dev command.

Manual Imports

For some edge cases (IDE support and libraries in node_modules) it is impossible to rely on auto imports.

You can import them from virtual #imports file. It will be still tree-shaken:

plugins/test.ts
import { useStorage } from '#imports'