React Native 基本命令匯總

最近進(jìn)行React Native的一些優(yōu)化工作锨阿,發(fā)現(xiàn)React Native提供了很多簡單方便的配置们豌,但是自己一直沒有使用過涯捻,而且React Native提供了非常好的help功能,會列出對應(yīng)的說明和example望迎,這邊簡單整理下一些常用的命令障癌。

1. 查看所有命令 react-native --help

mac:react-native --help

  Usage: react-native [options] [command]

  Options:

    -V, --version                      output the version number
    -h, --help                         output usage information

  Commands:

    start [options]                    starts the webserver
    run-ios [options]                  builds your app and starts it on iOS simulator
    run-android [options]              builds your app and starts it on a connected Android emulator or device
    new-library [options]              generates a native library bridge
    bundle [options]                   builds the javascript bundle for offline use
    unbundle [options]                 builds javascript as "unbundle" for offline use
    eject [options]                    Re-create the iOS and Android folders and native code
    link [options] [packageName]       links all native dependencies (updates native build files)
    unlink [options] <packageName>     unlink native dependency
    install [options] <packageName>    install and link native dependencies
    uninstall [options] <packageName>  uninstall and unlink native dependencies
    upgrade [options]                  upgrade your app's template files to the latest version; run this after updating the react-native version in your package.json and running npm install
    log-android [options]              starts adb logcat
    log-ios [options]                  starts iOS device syslog tail
    info [options]                     Get relevant version info about OS, toolchain and libraries

2. 最常用的啟動命令react-native start

mac:react-native start --help
react-native start [options]
  starts the webserver

  Options:

    --port [number]                                                (default: 8081)
    --host [string]                                                (default: )
    --root [list]                                                 add another root(s) to be used by the packager in this project (default: )
    --projectRoots [list]                                         override the root(s) to be used by the packager (default: /Users/mac/mallCategory)
    --assetExts [list]                                            Specify any additional asset extensions to be used by the packager (default: )
    --sourceExts [list]                                           Specify any additional source extensions to be used by the packager (default: )
    --platforms [list]                                            Specify any additional platforms to be used by the packager (default: )
    --providesModuleNodeModules [list]                            Specify any npm packages that import dependencies with providesModule (default: react-native,react-native-windows)
    --max-workers [number]                                        Specifies the maximum number of workers the worker-pool will spawn for transforming files. This defaults to the number of the cores available on your machine.
    --skipflow                                                    Disable flow checks
    --nonPersistent                                               Disable file watcher
    --transformer [string]                                        Specify a custom transformer to be used
    --reset-cache, --resetCache                                   Removes cached files
    --custom-log-reporter-path, --customLogReporterPath [string]  Path to a JavaScript file that exports a log reporter as a replacement for TerminalReporter
    --verbose                                                     Enables logging
    --https                                                       Enables https connections to the server
    --key [path]                                                  Path to custom SSL key
    --cert [path]                                                 Path to custom SSL cert
    --config [string]                                             Path to the CLI configuration file
    -h, --help                                                    output usage information

3. iOS啟動命令 react-native --run-ios

mac: react-native run-ios --help

  react-native run-ios [options]
  builds your app and starts it on iOS simulator

  Options:

    --simulator [string]      Explicitly set simulator to use (default: iPhone 6)
    --configuration [string]  Explicitly set the scheme configuration to use
    --scheme [string]         Explicitly set Xcode scheme to use
    --project-path [string]   Path relative to project root where the Xcode project (.xcodeproj) lives. The default is 'ios'. (default: ios)
    --device [string]         Explicitly set device to use by name.  The value is not required if you have a single device connected.
    --udid [string]           Explicitly set device to use by udid
    --no-packager             Do not launch packager while building
    --verbose                 Do not use xcpretty even if installed
    --config [string]         Path to the CLI configuration file
    -h, --help                output usage information

  Example usage:

    Run on a different simulator, e.g. iPhone 5:
    react-native run-ios --simulator "iPhone 5"

    Pass a non-standard location of iOS directory:
    react-native run-ios --project-path "./app/ios"

    Run on a connected device, e.g. Max's iPhone:
    react-native run-ios --device "Max's iPhone"

4. Android 啟動命令 react-native run-android

mac: react-native run-android --help

  react-native run-android [options]
  builds your app and starts it on a connected Android emulator or device

  Options:

    --install-debug
    --root [string]           Override the root directory for the android build (which contains the android directory) (default: )
    --flavor [string]         --flavor has been deprecated. Use --variant instead
    --variant [string]
    --appFolder [string]      Specify a different application folder name for the android source. (default: app)
    --appId [string]          Specify an applicationId to launch after build. (default: )
    --appIdSuffix [string]    Specify an applicationIdSuffix to launch after build. (default: )
    --main-activity [string]  Name of the activity to start (default: MainActivity)
    --deviceId [string]       builds your app and starts it on a specific device/simulator with the given device id (listed by running "adb devices" on the command line).
    --no-packager             Do not launch packager while building
    --port [number]            (default: 8081)
    --config [string]         Path to the CLI configuration file
    -h, --help                output usage information

5. 生成bundle文件 react-native bundle

mac: react-native bundle --help

  react-native bundle [options]
  builds the javascript bundle for offline use

  Options:

    --entry-file <path>                Path to the root JS file, either absolute or relative to JS root
    --platform [string]                Either "ios" or "android" (default: ios)
    --transformer [string]             Specify a custom transformer to be used
    --dev [boolean]                    If false, warnings are disabled and the bundle is minified (default: true)
    --bundle-output <string>           File name where to store the resulting bundle, ex. /tmp/groups.bundle
    --bundle-encoding [string]         Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer). (default: utf8)
    --max-workers [number]             Specifies the maximum number of workers the worker-pool will spawn for transforming files.This defaults to the number of the cores available on your machine.
    --sourcemap-output [string]        File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map
    --sourcemap-sources-root [string]  Path to make sourcemap's sources entries relative to, ex. /root/dir
    --sourcemap-use-absolute-path      Report SourceMapURL using its full path
    --assets-dest [string]             Directory name where to store assets referenced in the bundle
    --verbose                          Enables logging
    --reset-cache                      Removes cached files
    --read-global-cache                Try to fetch transformed JS code from the global cache, if configured.
    --config [string]                  Path to the CLI configuration file
    -h, --help                         output usage information

5. 生成unbundle文件 react-native unbundle

mac: react-native unbundle --help

  react-native unbundle [options]
  builds javascript as "unbundle" for offline use

  Options:

    --entry-file <path>                Path to the root JS file, either absolute or relative to JS root
    --platform [string]                Either "ios" or "android" (default: ios)
    --transformer [string]             Specify a custom transformer to be used
    --dev [boolean]                    If false, warnings are disabled and the bundle is minified (default: true)
    --bundle-output <string>           File name where to store the resulting bundle, ex. /tmp/groups.bundle
    --bundle-encoding [string]         Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer). (default: utf8)
    --max-workers [number]             Specifies the maximum number of workers the worker-pool will spawn for transforming files.This defaults to the number of the cores available on your machine.
    --sourcemap-output [string]        File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map
    --sourcemap-sources-root [string]  Path to make sourcemap's sources entries relative to, ex. /root/dir
    --sourcemap-use-absolute-path      Report SourceMapURL using its full path
    --assets-dest [string]             Directory name where to store assets referenced in the bundle
    --verbose                          Enables logging
    --reset-cache                      Removes cached files
    --read-global-cache                Try to fetch transformed JS code from the global cache, if configured.
    --indexed-unbundle                 Force indexed unbundle file format, even when building for android
    --config [string]                  Path to the CLI configuration file
    -h, --help                         output usage information

6. 查看React Native相關(guān)的信息 react-native info

mac: react-native info

Environment:
  OS: macOS High Sierra 10.13.6
  Node: 10.0.0
  Yarn: 1.9.4
  npm: 5.6.0
  Watchman: 4.7.0
  Xcode: Xcode 10.1 Build version 10B61
  Android Studio: 1.4 AI-141.2343393

Packages: (wanted => installed)
  react: 16.2.0
  react-native: 0.52.0
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市辩尊,隨后出現(xiàn)的幾起案子涛浙,更是在濱河造成了極大的恐慌,老刑警劉巖摄欲,帶你破解...
    沈念sama閱讀 219,539評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件轿亮,死亡現(xiàn)場離奇詭異,居然都是意外死亡胸墙,警方通過查閱死者的電腦和手機(jī)我注,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,594評論 3 396
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來迟隅,“玉大人但骨,你說我怎么就攤上這事≈窍” “怎么了奔缠?”我有些...
    開封第一講書人閱讀 165,871評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長吼野。 經(jīng)常有香客問我校哎,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,963評論 1 295
  • 正文 為了忘掉前任闷哆,我火速辦了婚禮腰奋,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘阳准。我一直安慰自己氛堕,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,984評論 6 393
  • 文/花漫 我一把揭開白布野蝇。 她就那樣靜靜地躺著讼稚,像睡著了一般。 火紅的嫁衣襯著肌膚如雪绕沈。 梳的紋絲不亂的頭發(fā)上锐想,一...
    開封第一講書人閱讀 51,763評論 1 307
  • 那天,我揣著相機(jī)與錄音乍狐,去河邊找鬼赠摇。 笑死,一個胖子當(dāng)著我的面吹牛浅蚪,可吹牛的內(nèi)容都是我干的藕帜。 我是一名探鬼主播,決...
    沈念sama閱讀 40,468評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼惜傲,長吁一口氣:“原來是場噩夢啊……” “哼洽故!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起盗誊,我...
    開封第一講書人閱讀 39,357評論 0 276
  • 序言:老撾萬榮一對情侶失蹤时甚,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后哈踱,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體荒适,經(jīng)...
    沈念sama閱讀 45,850評論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,002評論 3 338
  • 正文 我和宋清朗相戀三年开镣,在試婚紗的時候發(fā)現(xiàn)自己被綠了刀诬。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,144評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡邪财,死狀恐怖舅列,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情卧蜓,我是刑警寧澤,帶...
    沈念sama閱讀 35,823評論 5 346
  • 正文 年R本政府宣布把敞,位于F島的核電站弥奸,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏奋早。R本人自食惡果不足惜盛霎,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,483評論 3 331
  • 文/蒙蒙 一赠橙、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧愤炸,春花似錦期揪、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,026評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至诞仓,卻和暖如春缤苫,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背墅拭。 一陣腳步聲響...
    開封第一講書人閱讀 33,150評論 1 272
  • 我被黑心中介騙來泰國打工活玲, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人谍婉。 一個月前我還...
    沈念sama閱讀 48,415評論 3 373
  • 正文 我出身青樓舒憾,卻偏偏與公主長得像,于是被迫代替她去往敵國和親穗熬。 傳聞我的和親對象是個殘疾皇子镀迂,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,092評論 2 355

推薦閱讀更多精彩內(nèi)容

  • 控油的技巧有哪些呢?我們生活中有很多控油的方法,也很實(shí)用!下面大鵬給大家分享下幾個技巧 技巧1死陆、徹底凈化肌膚 洗臉...
    沈大鵬歐巴閱讀 276評論 0 0
  • 吃飯時喝湯是中國人的飲食習(xí)慣措译。人們幾乎天天都在說“喝湯”别凤,這是漢語中最常見、最規(guī)范的習(xí)語领虹」婺模可你知道嗎,在英語里塌衰,“...
    TonyRongEnglish閱讀 2,865評論 0 1
  • 回家第二天诉稍,就是公公的生日。 公公婆婆過生日最疆,除了自己親戚杯巨,還有要好的鄰居,一湊就最少兩桌努酸。有時候晚上還要叫叫白天...
    簡書作者木瓜閱讀 265評論 13 5