From a648958b00758bd267743090a894c510ecaa8b40 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Thu, 16 Jun 2022 19:24:48 +0800 Subject: [PATCH] fix: compatibility with Vue 2.7 --- packages/@vue/cli-plugin-typescript/index.js | 11 ++++++++++- packages/@vue/cli-service/lib/config/base.js | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/@vue/cli-plugin-typescript/index.js b/packages/@vue/cli-plugin-typescript/index.js index 54af685a4c..608c108769 100644 --- a/packages/@vue/cli-plugin-typescript/index.js +++ b/packages/@vue/cli-plugin-typescript/index.js @@ -82,6 +82,15 @@ 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 vueCompilerPath + try { + // Vue 2.7+ + vueCompilerPath = require.resolve('vue/compiler-sfc') + } catch (e) { + // Vue 2.6 and lower versions + vueCompilerPath = require.resolve('vue-template-compiler') + } + config .plugin('fork-ts-checker') .use(require('fork-ts-checker-webpack-plugin'), [{ @@ -89,7 +98,7 @@ module.exports = (api, projectOptions) => { extensions: { vue: { enabled: true, - compiler: isVue3 ? require.resolve('vue/compiler-sfc') : require.resolve('vue-template-compiler') + compiler: vueCompilerPath } }, diagnosticOptions: { diff --git a/packages/@vue/cli-service/lib/config/base.js b/packages/@vue/cli-service/lib/config/base.js index 3c8ff627bf..84bbfeddaa 100644 --- a/packages/@vue/cli-service/lib/config/base.js +++ b/packages/@vue/cli-service/lib/config/base.js @@ -64,9 +64,14 @@ module.exports = (api, options) => { const vueLoaderCacheConfig = api.genCacheConfig('vue-loader', { 'vue-loader': require('@vue/vue-loader-v15/package.json').version, '@vue/component-compiler-utils': require('@vue/component-compiler-utils/package.json').version, - 'vue-template-compiler': require('vue-template-compiler/package.json').version }) + try { + vueLoaderCacheConfig['vue-template-compiler'] = require('vue-template-compiler/package.json').version + } catch (e) { + // For Vue 2.7 projects, `vue-template-compiler` is not required + } + webpackConfig.resolve .alias .set(