From 5b5779254c4da1f3dab0098740a0164e3006b42a Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Mon, 27 Jun 2022 16:02:55 +0800 Subject: [PATCH] fix: typechecking with Vue 2.7+ Fixes #7213 --- packages/@vue/cli-plugin-typescript/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/@vue/cli-plugin-typescript/index.js b/packages/@vue/cli-plugin-typescript/index.js index a29101393a..00c70eca43 100644 --- a/packages/@vue/cli-plugin-typescript/index.js +++ b/packages/@vue/cli-plugin-typescript/index.js @@ -83,21 +83,24 @@ module.exports = (api, projectOptions) => { // this plugin does not play well with jest + cypress setup (tsPluginE2e.spec.js) somehow // so temporarily disabled for vue-cli tests if (!process.env.VUE_CLI_TEST) { - let compilerPath + let compilerPath; let useCompilerSFC = false try { // Vue 2.7+ compilerPath = require.resolve('vue/compiler-sfc') + useCompilerSFC = true } catch (e) { if (isVue3) { // Vue 3.0.0-3.2.12 compilerPath = require.resolve('@vue/compiler-sfc') + useCompilerSFC = true } else { // Vue <= 2.6 compilerPath = require.resolve('vue-template-compiler') } } - if (isVue3) { + if (useCompilerSFC) { + // only v5 supports the compiler-sfc API config .plugin('fork-ts-checker') .use(require('fork-ts-checker-webpack-plugin-v5'), [{ @@ -116,6 +119,7 @@ module.exports = (api, projectOptions) => { } }]) } else { + // fallback to v3, in order to not introduce breaking changes to legacy projects config .plugin('fork-ts-checker') .use(require('fork-ts-checker-webpack-plugin'), [{