Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

快速搭建 TypeScript 和 React Native 的开发环境 #5

Open
ljunb opened this issue Jan 17, 2018 · 2 comments
Open

快速搭建 TypeScript 和 React Native 的开发环境 #5

ljunb opened this issue Jan 17, 2018 · 2 comments

Comments

@ljunb
Copy link
Owner

ljunb commented Jan 17, 2018

  • 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';
@syanbo
Copy link

syanbo commented Mar 18, 2019

可以使用 --template
react-native init MyApp --template typescript

@ljunb
Copy link
Owner Author

ljunb commented Mar 18, 2019

@syanbo 新版功能咩,好久没关注

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants