mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 15:42:09 +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 () {
|
export function setupAutoImports () {
|
||||||
const nuxt = useNuxt()
|
const nuxt = useNuxt()
|
||||||
|
|
||||||
const bridgePresets: Preset[] = [
|
const bridgePresets: Preset[] = [{
|
||||||
{
|
from: '@vue/composition-api',
|
||||||
from: '@vue/composition-api',
|
imports: vuePreset.imports.filter(i => CapiHelpers.has(i as string))
|
||||||
imports: vuePreset.imports.filter(i => CapiHelpers.has(i as string))
|
}]
|
||||||
},
|
|
||||||
{
|
|
||||||
from: '#app',
|
|
||||||
imports: ['useNuxt2Meta']
|
|
||||||
}
|
|
||||||
]
|
|
||||||
nuxt.hook('autoImports:sources', (presets) => {
|
nuxt.hook('autoImports:sources', (presets) => {
|
||||||
const vuePreset = presets.find(p => p.from === 'vue')
|
const vuePreset = presets.find(p => p.from === 'vue')
|
||||||
if (vuePreset) { vuePreset.disabled = true }
|
if (vuePreset) { vuePreset.disabled = true }
|
||||||
})
|
|
||||||
|
|
||||||
nuxt.hook('autoImports:extend', (imports) => {
|
const appPreset = presets.find(p => p.from === '#app')
|
||||||
for (const i of imports) {
|
if (!appPreset) { return }
|
||||||
if (i.from === '#app' && UnsupportedImports.has(i.name)) {
|
|
||||||
i.disabled = true
|
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 }))
|
nuxt.hook('modules:done', () => installModule(autoImports, { presets: bridgePresets }))
|
||||||
|
Loading…
Reference in New Issue
Block a user