@@ -17,43 +17,75 @@ module.exports = (api, options) => {
1717 . add ( api . resolve ( 'src' ) )
1818 . add ( api . resolve ( 'test' ) )
1919 . 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
2620 . use ( 'cache-loader' )
2721 . loader ( 'cache-loader' )
2822 . options ( { cacheDirectory } )
2923 . end ( )
30- . use ( 'babel-loader' )
31- . loader ( 'babel-loader' )
3224
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
4145 if ( api . hasPlugin ( 'babel' ) ) {
4246 tsRule
43- . use ( 'cache-loader' )
44- . loader ( 'cache-loader' )
45- . options ( { cacheDirectory } )
46- . end ( )
4747 . use ( 'babel-loader' )
4848 . 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+ } )
4958 }
59+
60+ // apply ts-loader
5061 tsRule
5162 . use ( 'ts-loader' )
5263 . 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
5670 } )
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+ } )
5789 }
5890
5991 config
0 commit comments