Skip to content

Commit 8a413e6

Browse files
committed
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.
1 parent 38a7b0f commit 8a413e6

File tree

1 file changed

+9
-1
lines changed
  • packages/@vue/cli-plugin-typescript

1 file changed

+9
-1
lines changed

packages/@vue/cli-plugin-typescript/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,20 @@ module.exports = (api, projectOptions) => {
7777
})
7878

7979
if (!process.env.VUE_CLI_TEST) {
80+
// try to load `@vue/compiler-sfc` if the project is using Vue 3.
81+
// if it is not available, it uses `vue-template-compiler`
82+
let compiler = '@vue/compiler-sfc'
83+
try {
84+
require(compiler)
85+
} catch (e) {
86+
compiler = 'vue-template-compiler'
87+
}
8088
// this plugin does not play well with jest + cypress setup (tsPluginE2e.spec.js) somehow
8189
// so temporarily disabled for vue-cli tests
8290
config
8391
.plugin('fork-ts-checker')
8492
.use(require('fork-ts-checker-webpack-plugin'), [{
85-
vue: true,
93+
vue: { enabled: true, compiler },
8694
tslint: projectOptions.lintOnSave !== false && fs.existsSync(api.resolve('tslint.json')),
8795
formatter: 'codeframe',
8896
// https://github.com/TypeStrong/ts-loader#happypackmode-boolean-defaultfalse

0 commit comments

Comments
 (0)