• react-native-typescript-项目环境搭建


    1、yarn global add create-react-native-app   //全局安装
    2、create-react-native-app 项目名称
    3、yarn add typescript tslint -D
    4、yarn add @types/react @types/react-native @types/react-dom -D
    5、yarn add concurrently rimraf -D
    6、yarn add ts-jest @types/jest @types/react-test-renderer -D
    7、tsc --init

     8、tsconfig.json

     

    {    
    "compilerOptions": {
            "module":"es2015",
            "target": "es2015",
            "jsx": "react",
            "rootDir": "src",
            "outDir": "build",
            "allowSyntheticDefaultImports": true,
            "noImplicitAny": true,
            "sourceMap": true,
            "experimentalDecorators": true,
            "preserveConstEnums": true,
            "allowJs": true,
            "noUnusedLocals": true,
            "noUnusedParameters": true,
            "noImplicitReturns": true,
            "skipLibCheck": true,
            "moduleResolution":"Node"
        },
        "filesGlob": [
            "typings/index.d.ts",
            "src/**/*.ts",
            "src/**/*.tsx",
            "node_modules/typescript/lib/lib.es6.d.ts"
        ],
        "types": [
          "react",
          "react-dom",
          "react-native"
        ],
        "exclude":[
            "build", 
            "node_modules",
            "jest.config.js",
            "App.js"
            
        ],
        "compileOnSave": false
    }

    9yarn add react-native-scripts

    10package.json

    "scripts": {
        "start": "react-native-scripts start",
        "eject": "react-native-scripts eject",
        "android": "react-native-scripts android",
        "ios": "react-native-scripts ios",
        "test": "node node_modules/jest/bin/jest.js",
        "lint": "tslint src/**/*.ts",
        "tsc": "tsc",
        "clean": "rimraf build",
        "build": "yarn run clean && yarn run tsc --",
        "watch": "yarn run build -- -w",
        "watchAndRunAndroid": "concurrently "yarn run watch" "yarn run android"",
        "buildRunAndroid": "yarn run build && yarn run watchAndRunAndroid ",
        "watchAndRunIOS": "concurrently "yarn run watch" "yarn run ios"",
        "buildRunIOS": "yarn run build && yarn run watchAndRunIOS ",
        "watchAndStart": "concurrently "yarn run watch" "yarn run start"",
        "buildAndStart": "yarn run build && yarn run watchAndStart "
      }

    11package.json

    "main":"./node_modules/react-native-scripts/build/bin/crna-entry.js"

    12App.js

    import App from './build/App';
    export default App;

    13src -> App.tsx

    /* jshint esversion: 6 */
    import React, { Component } from "react"
    import { View, Text } from "react-native"
    
    export default class App extends Component {
      render() {
        return(
          <View>
            <Text>hello world</Text>
          </View>
        )
      }
    }

    14、将babel.config.js移动到src的目录中

     
  • 相关阅读:
    Flink资料(5) -- Job和调度
    Flink资料(4) -- 类型抽取和序列化
    Flink资料(3)-- Flink一般架构和处理模型
    Flink资料(2)-- 数据流容错机制
    Flink资料(1)-- Flink基础概念(Basic Concept)
    联系InfoSphere Streams和OpenMI时对水利模型联系的设计模式的一些考虑
    [Azure][CLI][02]Basic OPS
    [Azure][PowerShell][ARM][01]Connect
    [Azure][PowerShell][ASM][13]Reset Password
    [Azure][PowerShell][ASM][12]ACL
  • 原文地址:https://www.cnblogs.com/houjl/p/10081116.html
Copyright © 2020-2023  润新知