fix(webpack): client-side typechecking when ssr: false (#18828)

This commit is contained in:
Daniel Roe 2023-02-06 10:35:47 -08:00 committed by GitHub
parent 6ce5443a7a
commit d998c16bac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 4 deletions

View File

@ -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' }
}
}
}))
}
}
}

View File

@ -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' }
}
}
}))
}
}