const { transpileModule } = require ( `typescript` ) ; const path = require ( `path` ) ; const test = /\.tsx?$/ ; const compilerDefaults = { target : `esnext` , experimentalDecorators : true , jsx : `preserve` , } ; module . exports . resolvableExtensions = ( ) => [ `.ts` , `.tsx` ] ; module . exports . modifyWebpackConfig = ( { config } , { compilerOptions } ) => { const copts = Object . assign ( { } , compilerDefaults , compilerOptions , { module : `commonjs` , } ) ; let tsConfig = { } ; try { const tsConfigPath = path . resolve ( __dirname , '../../tsconfig.json' ) ; tsConfig = require ( tsConfigPath ) ; } catch ( e ) { console . error ( 'no tsconfig found' ) ; } console . log ( 'tsconfig' ) ; console . log ( tsConfig ) ; const opts = Object . assign ( { } , { compilerOptions : copts } , tsConfig ) ; const extractQueryPlugin = path . resolve ( __dirname , `../../node_modules/gatsby/dist/utils/babel-plugin-extract-graphql.js` ) ; config . loader ( `typescript` , { test , loaders : [ `babel?${ JSON . stringify ( { plugins : [ extractQueryPlugin ] } ) }` , `ts-loader?${ JSON . stringify ( opts ) }` , ] , } ) ; config . preLoader ( `typescript` , { test , loaders : [ `tslint-loader` ] } ) ; } ; module . exports . preprocessSource = ( { contents , filename } , { compilerOptions } ) => { const copts = Object . assign ( { } , compilerDefaults , compilerOptions , { target : `esnext` , module : `es6` , } ) ; return test . test ( filename ) ? transpileModule ( contents , { compilerOptions : copts } ) . outputText : null ; } ;