@@ -37,7 +37,7 @@ class ScratchWebpackConfigBuilder {
37
37
* @param {string|URL } [options.srcPath] The absolute path to the source files. Defaults to `src` under `rootPath`.
38
38
* @param {boolean } [options.shouldSplitChunks] Whether to enable spliting code to chunks.
39
39
*/
40
- constructor ( { distPath, enableReact, libraryName, rootPath, srcPath, shouldSplitChunks } ) {
40
+ constructor ( { distPath, enableReact, enableTs , libraryName, rootPath, srcPath, shouldSplitChunks } ) {
41
41
const isProduction = process . env . NODE_ENV === 'production' ;
42
42
const mode = isProduction ? 'production' : 'development' ;
43
43
@@ -90,6 +90,7 @@ class ScratchWebpackConfigBuilder {
90
90
'.jsx'
91
91
] : [ ]
92
92
) ,
93
+ ...( enableTs ? [ '.ts' , '.tsx' ] : [ ] ) ,
93
94
// webpack supports '...' to include defaults, but eslint does not
94
95
'.js' ,
95
96
'.json'
@@ -98,7 +99,9 @@ class ScratchWebpackConfigBuilder {
98
99
module : {
99
100
rules : [
100
101
{
101
- test : enableReact ? / \. [ c m ] ? j s x ? $ / : / \. [ c m ] ? j s $ / ,
102
+ test : enableReact ?
103
+ ( enableTs ? / \. [ c m ] ? [ j t ] s x ? $ / : / \. [ c m ] ? j s x ? $ / ) :
104
+ ( enableTs ? / \. [ c m ] ? [ j t ] s $ / : / \. [ c m ] ? j s $ / ) ,
102
105
loader : 'babel-loader' ,
103
106
exclude : [
104
107
{
@@ -196,7 +199,12 @@ class ScratchWebpackConfigBuilder {
196
199
]
197
200
}
198
201
] : [ ]
199
- )
202
+ ) ,
203
+ ...( enableTs ? [ {
204
+ test : enableReact ? / \. [ c m ] ? [ j t ] s x ? $ / : / \. [ c m ] ? [ j t ] s $ / ,
205
+ loader : 'ts-loader' ,
206
+ exclude : [ / n o d e _ m o d u l e s / ]
207
+ } ] : [ ] ) ,
200
208
] ,
201
209
202
210
} ,
0 commit comments