-
-
Save ktpm489/0043ff7dabb3fb7cacda7b361294d8e9 to your computer and use it in GitHub Desktop.
React Native typescript configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
module.exports = { | |
getAssetExts() { | |
return [ | |
'ts', | |
'tsx' | |
] | |
}, | |
getTransformModulePath() { | |
return path.join(__dirname, 'transformer.js'); | |
}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
let path = require('path'); | |
let ts = require('typescript'); | |
let tsConfig = require('./tsconfig.json'); | |
let rnTransform = require('react-native/packager/transformer').transform; | |
function transform(data, callback) { | |
// Do custom transformations | |
let result = data.sourceCode; | |
if (path.extname(data.filename) == '.tsx' || path.extname(data.filename) == '.ts') { | |
try { | |
result = ts.transpileModule(result, {compilerOptions: tsConfig.compilerOptions}); | |
result = result.outputText; | |
} catch(e) { | |
callback(e); | |
return; | |
} | |
} | |
// Pass the transformed source to the original react native transformer | |
try { | |
result = rnTransform(result, data.filename, data.options); | |
} catch(e) { | |
callback(e); | |
return; | |
} | |
callback(null, result); | |
} | |
module.exports = transform; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment