File tree 6 files changed +5210
-2
lines changed
6 files changed +5210
-2
lines changed Original file line number Diff line number Diff line change @@ -341,6 +341,21 @@ module.exports = {
341
341
return this ;
342
342
} ,
343
343
344
+ /**
345
+ * Call this if you plan on loading TypeScript files.
346
+ *
347
+ * Supported options:
348
+ * @see https://github.com/TypeStrong/ts-loader/blob/master/README.md#available-options
349
+ *
350
+ * @param {object } options
351
+ * @return {exports }
352
+ */
353
+ enableTypeScriptLoader ( options = { } ) {
354
+ webpackConfig . enableTypeScriptLoader ( options ) ;
355
+
356
+ return this ;
357
+ } ,
358
+
344
359
/**
345
360
* If enabled, the output directory is emptied between
346
361
* each build (to remove old files).
Original file line number Diff line number Diff line change @@ -51,6 +51,21 @@ class WebpackConfig {
51
51
this . babelConfigurationCallback = function ( ) { } ;
52
52
this . useReact = false ;
53
53
this . loaders = [ ] ;
54
+ this . useTypeScriptLoader = false ;
55
+ this . typeScriptOptions = {
56
+ transpileOnly : false ,
57
+ happyPackMode : false ,
58
+ logInfoToStdOut : false ,
59
+ logLevel : 'info' ,
60
+ silent : false ,
61
+ ignoreDiagnostics : [ ] ,
62
+ compiler : 'typescript' ,
63
+ configFileName : 'tsconfig.json' ,
64
+ visualStudioErrorFormat : false ,
65
+ compilerOptions : { } ,
66
+ entryFileIsJs : false ,
67
+ appendTsSuffixTo : [ ]
68
+ } ;
54
69
}
55
70
56
71
getContext ( ) {
@@ -222,6 +237,18 @@ class WebpackConfig {
222
237
this . useReact = true ;
223
238
}
224
239
240
+ enableTypeScriptLoader ( options = { } ) {
241
+ this . useTypeScriptLoader = true ;
242
+
243
+ for ( const optionKey of Object . keys ( options ) ) {
244
+ if ( ! ( optionKey in this . sassOptions ) ) {
245
+ throw new Error ( `Invalid option "${ optionKey } " passed to enableTypeScriptLoader(). Valid keys are ${ Object . keys ( this . typeScriptOptions ) . join ( ', ' ) } ` ) ;
246
+ }
247
+
248
+ this . typeScriptOptions [ optionKey ] = options [ optionKey ] ;
249
+ }
250
+ }
251
+
225
252
cleanupOutputBeforeBuild ( ) {
226
253
this . cleanupOutput = true ;
227
254
}
Original file line number Diff line number Diff line change @@ -154,6 +154,28 @@ class ConfigGenerator {
154
154
} ) ;
155
155
}
156
156
157
+ if ( this . webpackConfig . useTypeScriptLoader ) {
158
+ loaderFeatures . ensureLoaderPackagesExist ( 'typescript' ) ;
159
+
160
+ this . webpackConfig . addLoader ( {
161
+ test : / \. t s x ? $ / ,
162
+ exclude : / n o d e _ m o d u l e s / ,
163
+ use : [
164
+ {
165
+ loader : 'babel-loader' ,
166
+ // @see https://babeljs.io/docs/usage/api/#options
167
+ // @see https://github.com/babel/babel-loader#options
168
+ options : babelConfig
169
+ } ,
170
+ {
171
+ loader : 'ts-loader' ,
172
+ // @see https://github.com/TypeStrong/ts-loader/blob/master/README.md#available-options
173
+ options : this . webpackConfig . typeScriptOptions
174
+ }
175
+ ]
176
+ } ) ;
177
+ }
178
+
157
179
this . webpackConfig . loaders . forEach ( ( loader ) => {
158
180
rules . push ( loader ) ;
159
181
} ) ;
Original file line number Diff line number Diff line change @@ -35,6 +35,11 @@ const loaderFeatures = {
35
35
method : 'enableReactPreset()' ,
36
36
packages : [ 'babel-preset-react' ] ,
37
37
description : 'process React JS files'
38
+ } ,
39
+ typescript : {
40
+ method : 'enableTypeScriptLoader()' ,
41
+ packages : [ 'typescript' , 'ts-loaders' ] ,
42
+ description : 'process TypeScript files'
38
43
}
39
44
} ;
40
45
You can’t perform that action at this time.
0 commit comments