@@ -1320,6 +1320,50 @@ module.exports = {
1320
1320
} ) . to . throw ( 'wrong `tsconfig` path in fork plugin configuration (should be a relative or absolute path)' ) ;
1321
1321
} ) ;
1322
1322
1323
+ it ( 'TypeScript can be compiled by Babel' , ( done ) => {
1324
+ const config = createWebpackConfig ( 'www/build' , 'dev' ) ;
1325
+ config . setPublicPath ( '/build' ) ;
1326
+ config . addEntry ( 'main' , [ './js/render.ts' , './js/index.ts' ] ) ;
1327
+ config . configureBabel ( function ( config ) {
1328
+ config . presets = [
1329
+ [ '@babel/preset-env' , {
1330
+ 'targets' : {
1331
+ 'chrome' : 52 ,
1332
+ } ,
1333
+ } ] ,
1334
+ '@babel/typescript' , // required preset
1335
+ ] ;
1336
+ // not required, but recommended
1337
+ config . plugins = [ '@babel/proposal-class-properties' ] ;
1338
+ } ) ;
1339
+
1340
+ config . configureLoaderRule ( 'javascript' , loader => {
1341
+ loader . test = / .( j | t ) s x ? $ / ; // let Babel to run over .tsx? files too
1342
+ } ) ;
1343
+
1344
+ testSetup . runWebpack ( config , ( webpackAssert ) => {
1345
+ // check that babel-loader transformed the ts file
1346
+ webpackAssert . assertOutputFileContains (
1347
+ 'main.js' ,
1348
+ 'document.getElementById(\'app\').innerHTML =' ,
1349
+ ) ;
1350
+
1351
+ testSetup . requestTestPage (
1352
+ path . join ( config . getContext ( ) , 'www' ) ,
1353
+ [
1354
+ 'build/runtime.js' ,
1355
+ 'build/main.js' ,
1356
+ ] ,
1357
+ ( browser ) => {
1358
+
1359
+ // assert that the ts module rendered
1360
+ browser . assert . text ( '#app h1' , 'Welcome to Your TypeScript App' ) ;
1361
+ done ( ) ;
1362
+ } ,
1363
+ ) ;
1364
+ } ) ;
1365
+ } ) ;
1366
+
1323
1367
it ( 'When configured, Handlebars is compiled' , ( done ) => {
1324
1368
const config = createWebpackConfig ( 'www/build' , 'dev' ) ;
1325
1369
config . setPublicPath ( '/build' ) ;
0 commit comments