mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 21:55:11 +00:00
fix(bridge): exclude unsupported imports via autoImports:sources
(#4127)
This commit is contained in:
parent
f0714d78b0
commit
6276580aa4
@ -10,27 +10,25 @@ const CapiHelpers = new Set(Object.keys(CompositionApi))
|
||||
export function setupAutoImports () {
|
||||
const nuxt = useNuxt()
|
||||
|
||||
const bridgePresets: Preset[] = [
|
||||
{
|
||||
from: '@vue/composition-api',
|
||||
imports: vuePreset.imports.filter(i => CapiHelpers.has(i as string))
|
||||
},
|
||||
{
|
||||
from: '#app',
|
||||
imports: ['useNuxt2Meta']
|
||||
}
|
||||
]
|
||||
const bridgePresets: Preset[] = [{
|
||||
from: '@vue/composition-api',
|
||||
imports: vuePreset.imports.filter(i => CapiHelpers.has(i as string))
|
||||
}]
|
||||
|
||||
nuxt.hook('autoImports:sources', (presets) => {
|
||||
const vuePreset = presets.find(p => p.from === 'vue')
|
||||
if (vuePreset) { vuePreset.disabled = true }
|
||||
})
|
||||
|
||||
nuxt.hook('autoImports:extend', (imports) => {
|
||||
for (const i of imports) {
|
||||
if (i.from === '#app' && UnsupportedImports.has(i.name)) {
|
||||
i.disabled = true
|
||||
const appPreset = presets.find(p => p.from === '#app')
|
||||
if (!appPreset) { return }
|
||||
|
||||
for (const [index, i] of Object.entries(appPreset.imports).reverse()) {
|
||||
if (typeof i === 'string' && UnsupportedImports.has(i)) {
|
||||
appPreset.imports.splice(Number(index), 1)
|
||||
}
|
||||
}
|
||||
|
||||
appPreset.imports.push('useNuxt2Meta')
|
||||
})
|
||||
|
||||
nuxt.hook('modules:done', () => installModule(autoImports, { presets: bridgePresets }))
|
||||
|
Loading…
Reference in New Issue
Block a user