mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(webpack): client-side typechecking when ssr: false
(#18828)
This commit is contained in:
parent
6ce5443a7a
commit
d998c16bac
@ -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' }
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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' }
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user