react native編寫原生應用,不僅可以編寫android,還可以編寫ios,使得我們的編程,變得更加的簡潔,那其實搭建react native環境是非常簡單的,隨着互聯網的發展,那對於編寫的規范也變得更加的嚴格,比如說,出現的typescript,但是給編程也帶來一些麻煩,比如,實現同樣一個功能,我們需要寫更多的代碼,但優點也是很多的
1、使其更易於閱讀和調試。
2、為我們提供了ES6(ECMAScript 6)的所有優點,以及更高的工作效率。
3、可以幫助我們避免開發人員通過類型檢查代碼編寫JavaScript時經常遇到的痛苦錯誤。
等等,還有很多優點,小編就不一一介紹了
下面介紹react+ts環境搭建
①yarn global add create-react-native-app
②create-react-native-app 項目名稱
③yarn add typescript tslint -D
④yarn add @types/react @types/react-native @types/react-dom -D
⑤yarn add concurrently rimraf -D
⑥yarn add ts-jest @types/jest @types/react-test-renderer -D
⑦tsc --init 生成tsconfig.json文件
⑧下面附上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": false,
"noUnusedParameters": false,
"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
}
⑨yarn add react-native-scripts
⑩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.json文件的另一處配置
"main":"./node_modules/react-native-scripts/build/bin/crna-entry.js"
下面就可以創建自己的應用啦
希望對您有幫助!!!!!!!!!
{ |
|
"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 |
|
} |