feat(kit): add helper addAutoImport (#3030)

This commit is contained in:
Ricardo Gobbo de Souza 2022-02-03 08:31:15 -03:00 committed by GitHub
parent 09dc06e138
commit adc44a2d2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,23 @@
import type { AutoImport } from '../../schema/src/types/imports'
import { useNuxt } from './context'
import { assertNuxtCompatibility } from './compatibility'
export function addAutoImport (_autoImports: AutoImport | AutoImport[]) {
assertNuxtCompatibility({ bridge: true })
useNuxt().hook('autoImports:extend', (autoImports: AutoImport[]) => {
for (const composable of (Array.isArray(_autoImports) ? _autoImports : [_autoImports])) {
autoImports.push(composable)
}
})
}
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)
}
})
}

View File

@ -8,6 +8,7 @@ export * from './loader/config'
export * from './loader/nuxt'
// Utils
export * from './auto-import'
export * from './build'
export * from './compatibility'
export * from './components'