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