diff --git a/packages/vite/src/server.ts b/packages/vite/src/server.ts index 2b1b2ec107..fe99919aa2 100644 --- a/packages/vite/src/server.ts +++ b/packages/vite/src/server.ts @@ -1,4 +1,3 @@ -import { resolveTSConfig } from 'pkg-types' import { resolve } from 'pathe' import * as vite from 'vite' import vuePlugin from '@vitejs/plugin-vue' @@ -142,16 +141,6 @@ export async function buildServer (ctx: ViteBuildContext) { }) } - // Add type-checking - if (ctx.nuxt.options.typescript.typeCheck === true || (ctx.nuxt.options.typescript.typeCheck === 'build' && !ctx.nuxt.options.dev)) { - const checker = await import('vite-plugin-checker').then(r => r.default) - serverConfig.plugins!.push(checker({ - vueTsc: { - tsconfigPath: await resolveTSConfig(ctx.nuxt.options.rootDir) - } - })) - } - await ctx.nuxt.callHook('vite:extendConfig', serverConfig, { isClient: false, isServer: true }) const onBuild = () => ctx.nuxt.callHook('build:resources', wpfs) diff --git a/packages/vite/src/vite.ts b/packages/vite/src/vite.ts index ff2e969d55..6d70b3db0b 100644 --- a/packages/vite/src/vite.ts +++ b/packages/vite/src/vite.ts @@ -2,12 +2,13 @@ import * as vite from 'vite' import { join, resolve } from 'pathe' import type { Nuxt } from '@nuxt/schema' import type { InlineConfig, SSROptions } from 'vite' -import { logger, isIgnored, resolvePath } from '@nuxt/kit' +import { logger, isIgnored, resolvePath, addVitePlugin } from '@nuxt/kit' import type { Options } from '@vitejs/plugin-vue' import replace from '@rollup/plugin-replace' import { sanitizeFilePath } from 'mlly' import { withoutLeadingSlash } from 'ufo' import { filename } from 'pathe/utils' +import { resolveTSConfig } from 'pkg-types' import { buildClient } from './client' import { buildServer } from './server' import virtual from './plugins/virtual' @@ -102,6 +103,16 @@ export async function bundle (nuxt: Nuxt) { await nuxt.callHook('vite:extend', ctx) + // Add type-checking + if (ctx.nuxt.options.typescript.typeCheck === true || (ctx.nuxt.options.typescript.typeCheck === 'build' && !ctx.nuxt.options.dev)) { + const checker = await import('vite-plugin-checker').then(r => r.default) + addVitePlugin(checker({ + vueTsc: { + tsconfigPath: await resolveTSConfig(ctx.nuxt.options.rootDir) + } + }), { client: !nuxt.options.ssr, server: nuxt.options.ssr }) + } + nuxt.hook('vite:serverCreated', (server: vite.ViteDevServer, env) => { // Invalidate virtual modules when templates are re-generated ctx.nuxt.hook('app:templatesGenerated', () => {