Skip to content

Commit

Permalink
fix: support optional @vue/compiler-sfc
Browse files Browse the repository at this point in the history
  • Loading branch information
qmhc committed Oct 20, 2021
1 parent 89384f4 commit 34e1958
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -19,7 +19,6 @@
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"@vitejs/plugin-vue": "^1.9.3",
"@vue/compiler-sfc": "^3.2.20",
"chalk": "^4.1.2",
"commitizen": "^4.2.4",
"conventional-changelog-cli": "^2.1.1",
Expand Down
9 changes: 7 additions & 2 deletions src/compile.ts
Expand Up @@ -9,9 +9,14 @@ let compiler: typeof import('@vue/compiler-sfc')
function requireCompiler() {
if (!compiler) {
try {
compiler = require('@vue/compiler-sfc')
// Vue 3.2.13+ ships the SFC compiler directly under the `vue` package
compiler = require('vue/compiler-sfc')
} catch (e) {
throw new Error('@vue/compiler-sfc is not present in the dependency tree.\n')
try {
compiler = require('@vue/compiler-sfc')
} catch (e) {
throw new Error('@vue/compiler-sfc is not present in the dependency tree.\n')
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions yarn.lock
Expand Up @@ -1328,7 +1328,7 @@ __metadata:
languageName: node
linkType: hard

"@vue/compiler-sfc@npm:3.2.20, @vue/compiler-sfc@npm:^3.2.20":
"@vue/compiler-sfc@npm:3.2.20":
version: 3.2.20
resolution: "@vue/compiler-sfc@npm:3.2.20"
dependencies:
Expand Down Expand Up @@ -7849,7 +7849,6 @@ typescript@4.4.3:
"@typescript-eslint/eslint-plugin": ^4.33.0
"@typescript-eslint/parser": ^4.33.0
"@vitejs/plugin-vue": ^1.9.3
"@vue/compiler-sfc": ^3.2.20
chalk: ^4.1.2
commitizen: ^4.2.4
conventional-changelog-cli: ^2.1.1
Expand Down

0 comments on commit 34e1958

Please sign in to comment.