码迷,mamicode.com
首页 > 其他好文 > 详细

react-native 项目配置ts运行环境

时间:2018-12-01 23:48:32      阅读:662      评论:0      收藏:0      [点我收藏+]

标签:uil   文件中   try   const   mpi   conf   ios   ports   options   

#全局安装 create-react-native-app

yarn global add create-react-native-app

#创建项目

 create-react-native-app  my-app

#安装ts依赖

yarn add typescript tslint -D
  yarn add @types/react @types/react-native @types/react-dom -D

yarn add concurrently rimraf -D

#在根目录下创建一个tsconfig.json配置文件,或者tsc --init生成默认配置文件再修改,把下面代码贴上去

{
"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",
"baseUrl": "./",
"paths": {
"assets": ["./assets"]
}
},
"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",
"assets"
],
"compileOnSave": false
}

#配置脚本命令,记得先安装react-native-script

将下面代码配置在package.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 "
},

 

#最后最重要的在package文件中把入口地址修改
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js"
 
#把babel.config文件放在src下面,在src文件创建ts文件,开心的写项目吧
 
#yarn buildAndStart启动服务(复合命令)

react-native 项目配置ts运行环境

标签:uil   文件中   try   const   mpi   conf   ios   ports   options   

原文地址:https://www.cnblogs.com/w-819/p/10051349.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!