8000 fix: Vue 2.7 compatibility · vuejs/vue-cli@b454dda · GitHub
[go: up one dir, main page]

Skip to content

Commit b454dda

Browse files
committed
fix: Vue 2.7 compatibility
1 parent 58ff39c commit b454dda

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ module.exports = (api, projectOptions) => {
8383
// this plugin does not play well with jest + cypress setup (tsPluginE2e.spec.js) somehow
8484
// so temporarily disabled for vue-cli tests
8585
if (!process.env.VUE_CLI_TEST) {
86+
let compilerPath
87+
try {
88+
// Vue 2.7+
89+
compilerPath = require.resolve('vue/compiler-sfc')
90+
} catch (e) {
91+
if (isVue3) {
92+
// Vue 3.0.0-3.2.12
93+
compilerPath = require.resolve('@vue/compiler-sfc')
94+
} else {
95+
// Vue <= 2.6
96+
compilerPath = require.resolve('vue-template-compiler')
97+
}
98+
}
99+
86100
if (isVue3) {
87101
config
88102
.plugin('fork-ts-checker')
@@ -91,7 +105,7 @@ module.exports = (api, projectOptions) => {
91105
extensions: {
92106
vue: {
93107
enabled: true,
94-
compiler: '@vue/compiler-sfc'
108+
compiler: compilerPath
95109
}
96110
},
97111
diagnosticOptions: {
@@ -105,7 +119,7 @@ module.exports = (api, projectOptions) => {
105119
config
106120
.plugin('fork-ts-checker')
107121
.use(require('fork-ts-checker-webpack-plugin'), [{
108-
vue: { enabled: true, compiler: 'vue-template-compiler' },
122+
vue: { enabled: true, compiler: compilerPath },
109123
tslint: projectOptions.lintOnSave !== false && fs.existsSync(api.resolve('tslint.json')),
110124
formatter: 'codeframe',
111125
// https://github.com/TypeStrong/ts-loader#happypackmode-boolean-defaultfalse

packages/@vue/cli-plugin-typescript/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,16 @@
4040
"peerDependencies": {
4141
"@vue/cli-service": "^3.0.0 || ^4.0.0-0",
4242
"@vue/compiler-sfc": "^3.0.0-beta.14",
43-
"typescript": ">=2"
43+
"typescript": ">=2",
44+
"vue": "*",
45+
"vue-template-compiler": "^2.0.0"
4446
},
4547
"peerDependenciesMeta": {
4648
"@vue/compiler-sfc": {
4749
"optional": true
50+
},
51+
"vue-template-compiler": {
52+
"optional": true
4853
}
4954
},
5055
"devDependencies": {

packages/@vue/cli-service/lib/config/base.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,18 @@ module.exports = (api, options) => {
8383

8484
if (vue && semver.major(vue.version) === 2) {
8585
// for Vue 2 projects
86-
const vueLoaderCacheConfig = api.genCacheConfig('vue-loader', {
86+
const partialIdentifier = {
8787
'vue-loader': require('vue-loader/package.json').version,
8888
'@vue/component-compiler-utils': require('@vue/component-compiler-utils/package.json').version,
89-
'vue-template-compiler': require('vue-template-compiler/package.json').version
90-
})
89+
}
90+
91+
try {
92+
partialIdentifier['vue-template-compiler'] = require('vue-template-compiler/package.json').version
93+
} catch (e) {
94+
// For Vue 2.7 projects, `vue-template-compiler` is not required
95+
}
96+
97+
const vueLoaderCacheConfig = api.genCacheConfig('vue-loader', partialIdentifier)
9198

9299
webpackConfig.resolve
93100
.alias

0 commit comments

Comments
 (0)
0