From 8a6db589fec7323bdd2932755326f3bc42e7ba39 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 29 Nov 2021 11:16:08 +0000 Subject: [PATCH] feat(bridge): generate components declarations (#2174) --- packages/bridge/src/app.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/bridge/src/app.ts b/packages/bridge/src/app.ts index d785a3fd45..951fcd6fa3 100644 --- a/packages/bridge/src/app.ts +++ b/packages/bridge/src/app.ts @@ -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 [