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

Commit

Permalink
fix(vite): add type-checker to client build for ssr: false (#7930)
Browse files Browse the repository at this point in the history
Co-authored-by: Sébastien Chopin <seb@nuxtjs.com>
  • Loading branch information
danielroe and Atinux committed Oct 3, 2022
1 parent 6d3dc3b commit d25dafe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
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

0 comments on commit d25dafe

Please sign in to comment.