File tree Expand file tree Collapse file tree 3 files changed +32
-6
lines changed Expand file tree Collapse file tree 3 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,20 @@ module.exports = (api, projectOptions) => {
83
83
// this plugin does not play well with jest + cypress setup (tsPluginE2e.spec.js) somehow
84
84
// so temporarily disabled for vue-cli tests
85
85
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
+
86
100
if ( isVue3 ) {
87
101
config
88
102
. plugin ( 'fork-ts-checker' )
@@ -91,7 +105,7 @@ module.exports = (api, projectOptions) => {
91
105
extensions : {
92
106
vue : {
93
107
enabled : true ,
94
- compiler : '@vue/compiler-sfc'
108
+ compiler : compilerPath
95
109
}
96
110
} ,
97
111
diagnosticOptions : {
@@ -105,7 +119,7 @@ module.exports = (api, projectOptions) => {
105
119
config
106
120
. plugin ( 'fork-ts-checker' )
107
121
. use ( require ( 'fork-ts-checker-webpack-plugin' ) , [ {
108
- vue : { enabled : true , compiler : 'vue-template-compiler' } ,
122
+ vue : { enabled : true , compiler : compilerPath } ,
109
123
tslint : projectOptions . lintOnSave !== false && fs . existsSync ( api . resolve ( 'tslint.json' ) ) ,
110
124
formatter : 'codeframe' ,
111
125
// https://github.com/TypeStrong/ts-loader#happypackmode-boolean-defaultfalse
Original file line number Diff line number Diff line change 40
40
"peerDependencies" : {
41
41
"@vue/cli-service" : " ^3.0.0 || ^4.0.0-0" ,
42
42
"@vue/compiler-sfc" : " ^3.0.0-beta.14" ,
43
- "typescript" : " >=2"
43
+ "typescript" : " >=2" ,
44
+ "vue" : " *" ,
45
+ "vue-template-compiler" : " ^2.0.0"
44
46
},
45
47
"peerDependenciesMeta" : {
46
48
"@vue/compiler-sfc" : {
47
49
"optional" : true
50
+ },
51
+ "vue-template-compiler" : {
52
+ "optional" : true
48
53
}
49
54
},
50
55
"devDependencies" : {
Original file line number Diff line number Diff line change @@ -83,11 +83,18 @@ module.exports = (api, options) => {
83
83
84
84
if ( vue && semver . major ( vue . version ) === 2 ) {
85
85
// for Vue 2 projects
86
- const vueLoaderCacheConfig = api . genCacheConfig ( 'vue-loader' , {
86
+ const partialIdentifier = {
87
87
'vue-loader' : require ( 'vue-loader/package.json' ) . version ,
88
88
'@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 )
91
98
92
99
webpackConfig . resolve
93
100
. alias
You can’t perform that action at this time.
0 commit comments