Created
August 20, 2020 13:33
-
-
Save LeslieOA/46445c6311c27497b412400d905f1653 to your computer and use it in GitHub Desktop.
Expo TypeScript Absolute Path's
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
module.exports = function(api) { | |
api.cache(true); | |
return { | |
presets: ['babel-preset-expo'], | |
plugins: [ | |
[ | |
'module-resolver', | |
{ | |
root: ['./src'], | |
extensions: [ | |
'.ios.js', | |
'.android.js', | |
'.js', | |
'.ts', | |
'.tsx', | |
'.json' | |
], | |
alias: { | |
'tests': ['./tests/'], | |
'@components': './src/components', | |
'@views': './src/views', | |
'@assets': './src/assets', | |
} | |
} | |
] | |
] | |
}; | |
}; |
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
{ | |
"compilerOptions": { | |
"allowSyntheticDefaultImports": true, | |
"jsx": "react-native", | |
"lib": ["dom", "esnext"], | |
"moduleResolution": "node", | |
"noEmit": true, | |
"skipLibCheck": true, | |
"resolveJsonModule": true, | |
"strict": true, | |
"baseUrl": ".", | |
"paths": { | |
"*": ["src/*"], | |
"tests": ["tests/*"], | |
"@components/*": ["src/components/*"], | |
"@views/*": ["src/views/*"], | |
"@assets/*": ["src/assets/*"], | |
} | |
} | |
} |
Also note: it's worth installing Expo globally for further development: npm install -g expo-cli
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replace both the
babel.config.js
andtsconfig.json
in a new Expo TypeScript project with the above.The above assumes a
src
folder with the childrenassets
,components
andviews
.Import's are now:
import { Fancy } from '@components/FancyComponent'
, etc.For more options, see Using Custom Path Aliases with TypeScript