diff --git a/packages/nuxt/src/components/module.ts b/packages/nuxt/src/components/module.ts index 52248d0ad1..214746a982 100644 --- a/packages/nuxt/src/components/module.ts +++ b/packages/nuxt/src/components/module.ts @@ -1,6 +1,6 @@ import fs, { statSync } from 'node:fs' import { join, normalize, relative, resolve } from 'pathe' -import { addPluginTemplate, addTemplate, addVitePlugin, addWebpackPlugin, defineNuxtModule, logger, resolveAlias, updateTemplates } from '@nuxt/kit' +import { addPluginTemplate, addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, defineNuxtModule, logger, resolveAlias, updateTemplates } from '@nuxt/kit' import type { Component, ComponentsDir, ComponentsOptions } from 'nuxt/schema' import { distDir } from '../dirs' @@ -115,7 +115,7 @@ export default defineNuxtModule({ }) // components.d.ts - addTemplate(componentsTypeTemplate) + addTypeTemplate(componentsTypeTemplate) // components.plugin.mjs addPluginTemplate(componentsPluginTemplate) // component-names.mjs @@ -188,9 +188,8 @@ export default defineNuxtModule({ app.components = newComponents }) - nuxt.hook('prepare:types', ({ references, tsConfig }) => { + nuxt.hook('prepare:types', ({ tsConfig }) => { tsConfig.compilerOptions!.paths['#components'] = [resolve(nuxt.options.buildDir, 'components')] - references.push({ path: resolve(nuxt.options.buildDir, 'components.d.ts') }) }) // Watch for changes diff --git a/packages/nuxt/src/imports/module.ts b/packages/nuxt/src/imports/module.ts index c3fe0abdf8..dcd26b5c11 100644 --- a/packages/nuxt/src/imports/module.ts +++ b/packages/nuxt/src/imports/module.ts @@ -1,5 +1,5 @@ import { existsSync } from 'node:fs' -import { addTemplate, addVitePlugin, addWebpackPlugin, defineNuxtModule, isIgnored, logger, resolveAlias, tryResolveModule, updateTemplates, useNuxt } from '@nuxt/kit' +import { addTemplate, addTypeTemplate, addVitePlugin, addWebpackPlugin, defineNuxtModule, isIgnored, logger, resolveAlias, tryResolveModule, updateTemplates, useNuxt } from '@nuxt/kit' import { isAbsolute, join, normalize, relative, resolve } from 'pathe' import type { Import, Unimport } from 'unimport' import { createUnimport, scanDirExports, toExports } from 'unimport' @@ -124,12 +124,6 @@ export default defineNuxtModule>({ // Generate types addDeclarationTemplates(ctx, options) - // Add generated types to `nuxt.d.ts` - nuxt.hook('prepare:types', ({ references }) => { - references.push({ path: resolve(nuxt.options.buildDir, 'types/imports.d.ts') }) - references.push({ path: resolve(nuxt.options.buildDir, 'imports.d.ts') }) - }) - // Watch composables/ directory nuxt.hook('builder:watch', async (_, relativePath) => { const path = resolve(nuxt.options.srcDir, relativePath) @@ -186,12 +180,12 @@ function addDeclarationTemplates (ctx: Unimport, options: Partial toExports(await ctx.getImports(), nuxt.options.buildDir, true) }) - addTemplate({ + addTypeTemplate({ filename: 'types/imports.d.ts', getContents: async () => { const imports = await ctx.getImports()