2021-10-02 16:59:32 +00:00
|
|
|
import { installModule, useNuxt } from '@nuxt/kit'
|
2021-11-05 14:39:14 +00:00
|
|
|
import * as CompositionApi from '@vue/composition-api'
|
2021-10-11 08:07:27 +00:00
|
|
|
import autoImports from '../../nuxt3/src/auto-imports/module'
|
2021-10-02 16:59:32 +00:00
|
|
|
|
2021-10-18 13:39:53 +00:00
|
|
|
const UnsupportedImports = new Set(['useAsyncData', 'useFetch'])
|
2021-11-05 14:39:14 +00:00
|
|
|
const CapiHelpers = new Set(Object.keys(CompositionApi))
|
2021-10-02 16:59:32 +00:00
|
|
|
|
2021-10-18 13:39:53 +00:00
|
|
|
const ImportRewrites = {
|
2021-12-17 09:15:03 +00:00
|
|
|
vue: '@vue/composition-api'
|
2021-10-02 16:59:32 +00:00
|
|
|
}
|
|
|
|
|
2021-10-11 08:07:27 +00:00
|
|
|
export async function setupAutoImports () {
|
2021-10-02 16:59:32 +00:00
|
|
|
const nuxt = useNuxt()
|
2021-10-18 13:39:53 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2021-11-05 14:39:14 +00:00
|
|
|
if (autoImport.from === '@vue/composition-api' && !CapiHelpers.has(autoImport.name)) {
|
|
|
|
autoImport.disabled = true
|
|
|
|
}
|
2021-10-18 13:39:53 +00:00
|
|
|
}
|
2021-11-09 10:17:56 +00:00
|
|
|
|
2021-12-17 09:15:03 +00:00
|
|
|
// Add auto-imports that are added by ad-hoc modules in nuxt 3
|
|
|
|
autoImports.push({ name: 'useRouter', as: 'useRouter', from: '#app' })
|
|
|
|
autoImports.push({ name: 'useRoute', as: 'useRoute', from: '#app' })
|
|
|
|
|
2021-11-09 10:17:56 +00:00
|
|
|
// Add bridge-only auto-imports
|
|
|
|
autoImports.push({ name: 'useNuxt2Meta', as: 'useNuxt2Meta', from: '#app' })
|
2021-10-18 13:39:53 +00:00
|
|
|
})
|
|
|
|
|
2021-12-21 13:57:26 +00:00
|
|
|
await installModule(autoImports)
|
2021-10-02 16:59:32 +00:00
|
|
|
}
|