rn-relates
rn-relates copied to clipboard
快速搭建 TypeScript 和 React Native 的开发环境
trafficstars
- 1 新建一个 React Native 项目,并
cd到根目录; - 2 添加必要的依赖:
yarn add @types/react @types/react-native
yarn add --dev react-native-typescript-transformer typescript
or
npm install --save @types/react @types/react-native
npm install --save-dev react-native-typescript-transformer typescript
- 3 新建
tsconfig.json文件:
{
"compilerOptions": {
"module": "es2015",
"target": "es2015",
"jsx": "react-native",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
}
}
- 4 新建
rn-cli.config.js文件:
module.exports = {
getTransformModulePath() {
return require.resolve('react-native-typescript-transformer');
},
getSourceExts() {
return ['ts', 'tsx'];
},
};
- 5 新建测试页面,以
tsx为后缀命名,修改 React 的引用方式:
import * as React from 'react';
import { Component } from 'react';
可以使用 --template react-native init MyApp --template typescript
@syanbo 新版功能咩,好久没关注