Nitro 使用 unjs/unimport 在与完整的 tree-shaking 支持一起使用时自动导入实用程序。
可用的自动导入
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)
检查 源代码 以获取可用的自动导入列表。
启用 TypeScript 后,您可以轻松地将它们视为 IDE 中的全局实用程序。
在运行 prepare
或 dev
命令时,这些类型是为全局自动导入自动生成的。
手动导入
对于某些边缘情况(IDE 支持和 node_modules
中的库),不可能依赖自动导入。
您可以从虚拟的“#imports”文件中导入它们。 它仍然会被 tree-shaking:
plugins/test.ts
js
import { useStorage } from '#imports'