Nuxt/packages/kit/src/auto-import.ts
2022-03-11 09:09:11 +01:00

22 lines
699 B
TypeScript

import { Import } from 'unimport'
import { useNuxt } from './context'
import { assertNuxtCompatibility } from './compatibility'
export function addAutoImport (imports: Import | Import[]) {
assertNuxtCompatibility({ bridge: true })
useNuxt().hook('autoImports:extend', (autoImports) => {
autoImports.push(...(Array.isArray(imports) ? imports : [imports]))
})
}
export function addAutoImportDir (_autoImportDirs: string | string[]) {
assertNuxtCompatibility({ bridge: true })
useNuxt().hook('autoImports:dirs', (autoImportDirs: string[]) => {
for (const dir of (Array.isArray(_autoImportDirs) ? _autoImportDirs : [_autoImportDirs])) {
autoImportDirs.push(dir)
}
})
}