From 34e19587aa64c802cfbd99c5c8018bde8d0e1e2f Mon Sep 17 00:00:00 2001 From: rk_zhang <40221744+qmhc@users.noreply.github.com> Date: Wed, 20 Oct 2021 11:02:32 +0800 Subject: [PATCH] fix: support optional @vue/compiler-sfc --- package.json | 1 - src/compile.ts | 9 +++++++-- yarn.lock | 3 +-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 8dcc69a..0f46a02 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/compile.ts b/src/compile.ts index a3276a9..39f63e4 100644 --- a/src/compile.ts +++ b/src/compile.ts @@ -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') + } } } diff --git a/yarn.lock b/yarn.lock index c594c24..357feef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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: @@ -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