From 8a413e66aabf3ba7048f693aec277b506f2f99a5 Mon Sep 17 00:00:00 2001 From: cexbrayat Date: Sun, 9 Feb 2020 19:28:00 +0100 Subject: [PATCH] feat: use @vue/compiler-sfc as a s compiler for TS if available The `fork-ts-checker-webpack-plugin` is using `vue-template-compiler` by default, and this compiler is not the correct one to pick for vue-next. This commit tries to load `@vue/compiler-sfc` and falls back to `vue-template-compiler` if it does not find it. --- packages/@vue/cli-plugin-typescript/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/@vue/cli-plugin-typescript/index.js b/packages/@vue/cli-plugin-typescript/index.js index be65dff5b7..09d727e857 100644 --- a/packages/@vue/cli-plugin-typescript/index.js +++ b/packages/@vue/cli-plugin-typescript/index.js @@ -77,12 +77,20 @@ module.exports = (api, projectOptions) => { }) if (!process.env.VUE_CLI_TEST) { + // try to load `@vue/compiler-sfc` if the project is using Vue 3. + // if it is not available, it uses `vue-template-compiler` + let compiler = '@vue/compiler-sfc' + try { + require(compiler) + } catch (e) { + compiler = 'vue-template-compiler' + } // this plugin does not play well with jest + cypress setup (tsPluginE2e.spec.js) somehow // so temporarily disabled for vue-cli tests config .plugin('fork-ts-checker') .use(require('fork-ts-checker-webpack-plugin'), [{ - vue: true, + vue: { enabled: true, compiler }, tslint: projectOptions.lintOnSave !== false && fs.existsSync(api.resolve('tslint.json')), formatter: 'codeframe', // https://github.com/TypeStrong/ts-loader#happypackmode-boolean-defaultfalse