26
loading...
This website collects cookies to deliver better user experience
TLDR You can use one command expo init --template @vladimir-vovk/expo-bare-typescript
to create new React Native project with all tools already setup for you (see README for details) or follow instructions below. 🤓
npm install --global expo-cli
or yarn global add expo-cli
.Expo CLI
: "managed workflow" and "bare workflow". Let's briefly look into each variant further. For more in depth comparison please read the official Expo doc.expo init
command.blank (TypeScript)
template.cd <your-project-name>
.yarn start
to start Metro Bundler.i
to start the iOS simulator or a
to run the Android emulator.expo init
command.minimal
template.cd <your-project-name>
.yarn start
.yarn ios
or yarn android
commands to build and run the app on the iOS simulator or Android emulator.📱tsconfig.json
file in your project root: touch tsconfig.json
.App.js
to App.tsx
: mv App.js App.tsx
.yarn start
. It will prompt you to install the required dependencies (typescript
, @types/react
, @types/react-native
), and automatically configure your tsconfig.json
.import { ComponentA } from 'src/components/A'
(notice path starts with src
), we need to add baseUrl
and paths
parameters to tsconfig.json
.{
...
"baseUrl": "./",
"paths": {
"src/*": ["src/*"]
}
...
}
src/package.json
file.{
"name": "src"
}
App.tsx
to src
with mv App.tsx src
command.index.js
....
import App from 'src/App'
...
module.exports = {
semi: false,
trailingComma: 'none',
singleQuote: true,
printWidth: 100,
tabWidth: 2,
useTabs: false,
}
babel.config.js
(line 4).module.exports = function(api) {
api.cache(true);
return {
presets: [['babel-preset-expo', { jsxRuntime: 'automatic' }]]
};
};
Ctrl-C
to stop it and run yarn start
to start Metro Bundler again.check-typescript
script to our package.json
....
"scripts": {
...
"check-typescript": "tsc --noEmit"
},
...
yarn check-typescript
command to check our code for errors with TypeScript compiler.yarn add --dev eslint-config-universe
yarn add --dev eslint prettier @typescript-eslint/eslint-plugin @typescript-eslint/parser
yarn add --dev eslint-plugin-react-hooks
yarn add --dev eslint-import-resolver-typescript
.eslintrc.js
config file to the project root.module.exports = {
extends: ['universe', 'universe/shared/typescript-analysis', 'plugin:react-hooks/recommended'],
overrides: [
{
files: ['*.ts', '*.tsx', '*.d.ts'],
parserOptions: {
project: './tsconfig.json'
}
}
],
settings: {
'import/resolver': {
typescript: {} // this loads <rootdir>/tsconfig.json to eslint
}
}
}
check-eslint
script to our package.json
....
"scripts": {
...
"check-eslint": "eslint './src/**/*{js,ts,jsx,tsx}'"
},
...
yarn check-eslint
command to check our code for errors with ESLint. And yarn check-eslint --fix
to fix errors automatically.lint
script to our package.json
....
"scripts": {
...
"lint": "yarn check-typescript && yarn check-eslint"
},
...