Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(vite): add type-checker to client build for ssr: false #7930

Merged
merged 2 commits into from Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 0 additions & 11 deletions 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'
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion packages/vite/src/vite.ts
Expand Up @@ -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'
Expand Down Expand Up @@ -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', () => {
Expand Down