mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-07 09:22:27 +00:00
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { installModule, useNuxt } from '@nuxt/kit'
|
|
import * as CompositionApi from '@vue/composition-api'
|
|
import autoImports from '../../nuxt3/src/auto-imports/module'
|
|
|
|
const UnsupportedImports = new Set(['useAsyncData', 'useFetch'])
|
|
const CapiHelpers = new Set(Object.keys(CompositionApi))
|
|
|
|
const ImportRewrites = {
|
|
vue: '@vue/composition-api',
|
|
'vue-router': '#app'
|
|
}
|
|
|
|
export async function setupAutoImports () {
|
|
const nuxt = useNuxt()
|
|
|
|
nuxt.hook('autoImports:extend', (autoImports) => {
|
|
for (const autoImport of autoImports) {
|
|
// Rewrite imports
|
|
if (autoImport.from in ImportRewrites) {
|
|
autoImport.from = ImportRewrites[autoImport.from]
|
|
}
|
|
// Disable unsupported imports
|
|
if (UnsupportedImports.has(autoImport.name)) {
|
|
autoImport.disabled = true
|
|
}
|
|
if (autoImport.from === '@vue/composition-api' && !CapiHelpers.has(autoImport.name)) {
|
|
autoImport.disabled = true
|
|
}
|
|
}
|
|
|
|
// Add bridge-only auto-imports
|
|
autoImports.push({ name: 'useNuxt2Meta', as: 'useNuxt2Meta', from: '#app' })
|
|
})
|
|
|
|
await installModule(nuxt, autoImports)
|
|
}
|