Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use @vue/compiler-sfc as a compiler for TS if available #5170

Merged
merged 2 commits into from Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/@vue/cli-plugin-typescript/index.js
Expand Up @@ -77,12 +77,24 @@ 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.resolve(compiler)
// use a shim as @vue/compiler-sfc does not offer the `parseComponent` function
// but a `parse` function
// the shim only delegates to the parse function
compiler = '@vue/cli-plugin-typescript/vue-compiler-sfc-shim'
cexbrayat marked this conversation as resolved.
Show resolved Hide resolved
} 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
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-plugin-typescript/package.json
Expand Up @@ -26,7 +26,7 @@
"@types/webpack-env": "^1.15.1",
"@vue/cli-shared-utils": "^4.2.3",
"cache-loader": "^4.1.0",
"fork-ts-checker-webpack-plugin": "^1.5.1",
"fork-ts-checker-webpack-plugin": "^3.1.1",
"globby": "^9.2.0",
"thread-loader": "^2.1.3",
"ts-loader": "^6.2.1",
Expand Down
7 changes: 7 additions & 0 deletions packages/@vue/cli-plugin-typescript/vue-compiler-sfc-shim.js
@@ -0,0 +1,7 @@
const compilerSFC = require('@vue/compiler-sfc')

module.exports = {
parseComponent (content, options) {
return compilerSFC.parse(content, options)
}
}