@@ -17,43 +17,75 @@ module.exports = (api, options) => {
17
17
. add ( api . resolve ( 'src' ) )
18
18
. add ( api . resolve ( 'test' ) )
19
19
. end ( )
20
-
21
- if ( options . experimentalCompileTsWithBabel ) {
22
- // Experimental: compile TS with babel so that it can leverage
23
- // preset-env for auto-detected polyfills based on browserslists config.
24
- // this is pending on the readiness of @babel /preset-typescript.
25
- tsRule
26
20
. use ( 'cache-loader' )
27
21
. loader ( 'cache-loader' )
28
22
. options ( { cacheDirectory } )
29
23
. end ( )
30
- . use ( 'babel-loader' )
31
- . loader ( 'babel-loader' )
32
24
33
- config . module
34
- . rule ( 'vue' )
35
- . use ( 'vue-loader' )
36
- . tap ( options => {
37
- options . loaders . ts = 'babel-loader'
38
- return options
39
- } )
40
- } else {
25
+ const vueLoader = config . module
26
+ . rule ( 'vue' )
27
+ . use ( 'vue-loader' )
28
+ . tap ( options => {
29
+ options . loaders . ts = [
30
+ {
31
+ loader : 'cache-loader' ,
32
+ options : { cacheDirectory }
33
+ }
34
+ ]
35
+ return options
36
+ } )
37
+
38
+ if ( ! options . experimentalCompileTsWithBabel ) {
39
+ const tsLoaderOptions = {
40
+ transpileOnly : true ,
41
+ appendTsSuffixTo : [ / \. v u e $ / ]
42
+ }
43
+
44
+ // if has babel plugin, inject babel-loader before ts-loader
41
45
if ( api . hasPlugin ( 'babel' ) ) {
42
46
tsRule
43
- . use ( 'cache-loader' )
44
- . loader ( 'cache-loader' )
45
- . options ( { cacheDirectory } )
46
- . end ( )
47
47
. use ( 'babel-loader' )
48
48
. loader ( 'babel-loader' )
49
+ vueLoader
50
+ . tap ( options => {
51
+ if ( api . hasPlugin ( 'babel' ) ) {
52
+ options . loaders . ts . push ( {
53
+ loader : 'babel-loader'
54
+ } )
55
+ }
56
+ return options
57
+ } )
49
58
}
59
+
60
+ // apply ts-loader
50
61
tsRule
51
62
. use ( 'ts-loader' )
52
63
. loader ( 'ts-loader' )
53
- . options ( {
54
- transpileOnly : true ,
55
- appendTsSuffixTo : [ / \. v u e $ / ]
64
+ . options ( tsLoaderOptions )
65
+ vueLoader
66
+ . tap ( options => {
67
+ options . loaders . ts . push ( {
68
+ loader : 'ts-loader' ,
69
+ options : tsLoaderOptions
56
70
} )
71
+ return options
72
+ } )
73
+ } else {
74
+ // Experimental: compile TS with babel so that it can leverage
75
+ // preset-env for auto-detected polyfills based on browserslists config.
76
+ // this is pending on the readiness of @babel /preset-typescript.
77
+ tsRule
78
+ . use ( 'babel-loader' )
79
+ . loader ( 'babel-loader' )
80
+ vueLoader
81
+ . tap ( options => {
82
+ options . loaders . ts . push (
83
+ {
84
+ loader : 'babel-loader'
85
+ }
86
+ )
87
+ return options
88
+ } )
57
89
}
58
90
59
91
config
0 commit comments