mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
feat(kit): add addImportsSources
utility (#7270)
This commit is contained in:
parent
396d55edb8
commit
a931667111
@ -1,4 +1,5 @@
|
||||
import { Import } from 'unimport'
|
||||
import type { Import } from 'unimport'
|
||||
import type { ImportPresetWithDeprecation } from '@nuxt/schema'
|
||||
import { useNuxt } from './context'
|
||||
import { assertNuxtCompatibility } from './compatibility'
|
||||
|
||||
@ -31,3 +32,14 @@ export function addImportsDir (dirs: string | string[]) {
|
||||
* @deprecated Please use `addImportsDir` instead with nuxt>=3.0.0-rc.9
|
||||
*/
|
||||
export const addAutoImportDir = addImportsDir
|
||||
|
||||
export function addImportsSources (presets: ImportPresetWithDeprecation | ImportPresetWithDeprecation[]) {
|
||||
assertNuxtCompatibility({ bridge: true })
|
||||
|
||||
// TODO: Use imports:* when widely adopted
|
||||
useNuxt().hook('autoImports:sources', (_presets: ImportPresetWithDeprecation[]) => {
|
||||
for (const preset of (Array.isArray(presets) ? presets : [presets])) {
|
||||
_presets.push(preset)
|
||||
}
|
||||
}, { allowDeprecated: true })
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ async function initNuxt (nuxt: Nuxt) {
|
||||
nuxt.hooks.deprecateHooks({
|
||||
'autoImports:sources': {
|
||||
to: 'imports:sources',
|
||||
message: '`autoImports:sources` hook is deprecated. Use `imports:sources` with `nuxt>=3.0.0-rc.9`.'
|
||||
message: '`autoImports:sources` hook is deprecated. Use `addImportsSources()` from `@nuxt/kit` or `imports:dirs` with `nuxt>=3.0.0-rc.10`.'
|
||||
},
|
||||
'autoImports:dirs': {
|
||||
to: 'imports:dirs',
|
||||
|
Loading…
Reference in New Issue
Block a user