diff --git a/packages/webpack/src/configs/client.ts b/packages/webpack/src/configs/client.ts index d3c35336e4..d7ca8f0fdf 100644 --- a/packages/webpack/src/configs/client.ts +++ b/packages/webpack/src/configs/client.ts @@ -2,8 +2,10 @@ import querystring from 'node:querystring' import { resolve } from 'pathe' import webpack from 'webpack' import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer' - +import { logger } from '@nuxt/kit' import { joinURL } from 'ufo' +import ForkTSCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin' + import type { WebpackConfigContext } from '../utils/config' import { applyPresets } from '../utils/config' import { nuxt } from '../presets/nuxt' @@ -86,8 +88,7 @@ function clientPlugins (ctx: WebpackConfigContext) { if (!ctx.isDev && ctx.name === 'client' && options.webpack.analyze) { const statsDir = resolve(options.buildDir, 'stats') - // @ts-ignore - config.plugins.push(new BundleAnalyzerPlugin({ + config.plugins!.push(new BundleAnalyzerPlugin({ analyzerMode: 'static', defaultSizes: 'gzip', generateStatsFile: true, @@ -97,4 +98,19 @@ function clientPlugins (ctx: WebpackConfigContext) { ...options.webpack.analyze === true ? {} : options.webpack.analyze })) } + + // Normally type checking runs in server config, but in `ssr: false` there is + // no server build, so we inject here instead. + if (!ctx.nuxt.options.ssr) { + if (ctx.nuxt.options.typescript.typeCheck === true || (ctx.nuxt.options.typescript.typeCheck === 'build' && !ctx.nuxt.options.dev)) { + config.plugins!.push(new ForkTSCheckerWebpackPlugin({ + logger, + typescript: { + extensions: { + vue: { compiler: '@vue/compiler-sfc' } + } + } + })) + } + } } diff --git a/packages/webpack/src/configs/server.ts b/packages/webpack/src/configs/server.ts index 8a7f4d3c8e..8ae872abe7 100644 --- a/packages/webpack/src/configs/server.ts +++ b/packages/webpack/src/configs/server.ts @@ -90,6 +90,13 @@ function serverPlugins (ctx: WebpackConfigContext) { // Add type-checking if (ctx.nuxt.options.typescript.typeCheck === true || (ctx.nuxt.options.typescript.typeCheck === 'build' && !ctx.nuxt.options.dev)) { - config.plugins.push(new ForkTSCheckerWebpackPlugin({ logger })) + config.plugins!.push(new ForkTSCheckerWebpackPlugin({ + logger, + typescript: { + extensions: { + vue: { compiler: '@vue/compiler-sfc' } + } + } + })) } }