feat(bridge): generate components declarations (#2174)

This commit is contained in:
Daniel Roe 2021-11-29 11:16:08 +00:00 committed by GitHub
parent ae6f095ee8
commit 8a6db589fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
import { useNuxt, resolveModule } from '@nuxt/kit'
import { useNuxt, resolveModule, addTemplate } from '@nuxt/kit'
import { resolve } from 'pathe'
import { componentsTypeTemplate } from '../../nuxt3/src/components/templates'
import { distDir } from './dirs'
export function setupAppBridge (_options: any) {
@ -17,6 +18,21 @@ export function setupAppBridge (_options: any) {
nuxt.options.fetch.server = false
nuxt.options.fetch.client = false
// Setup types for components
const components = []
nuxt.hook('components:extend', (registeredComponents) => {
components.push(...registeredComponents)
})
addTemplate({
...componentsTypeTemplate,
options: { components, buildDir: nuxt.options.buildDir }
})
nuxt.hook('prepare:types', ({ references }) => {
if (components.length) {
references.push({ path: resolve(nuxt.options.buildDir, 'components.d.ts') })
}
})
// Alias vue to have identical vue3 exports
nuxt.options.alias['vue2-bridge'] = resolve(distDir, 'runtime/vue2-bridge.mjs')
for (const alias of [