mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
00599ee327
Deploy website version based on e28868efdc29abc411db96d3c572f8d4cf8eee25
84 lines
16 KiB
HTML
84 lines
16 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><title>Understanding the CLI · React Native</title><meta name="viewport" content="width=device-width"/><meta name="generator" content="Docusaurus"/><meta name="description" content="<p>Though you may have installed the <code>react-native-cli</code> via npm as a separate module, it is a shell for accessing the CLI embedded in the React Native of each project. Your commands and their effects are dependent on the version of the module of <code>react-native</code> in context of the project. This guide will give a brief overview of the CLI in the module.</p>
|
|
"/><meta name="docsearch:version" content="0.59"/><meta name="docsearch:language" content="en"/><meta property="og:title" content="Understanding the CLI · React Native"/><meta property="og:type" content="website"/><meta property="og:url" content="https://facebook.github.io/react-native/"/><meta property="og:description" content="<p>Though you may have installed the <code>react-native-cli</code> via npm as a separate module, it is a shell for accessing the CLI embedded in the React Native of each project. Your commands and their effects are dependent on the version of the module of <code>react-native</code> in context of the project. This guide will give a brief overview of the CLI in the module.</p>
|
|
"/><meta name="twitter:card" content="summary"/><link rel="shortcut icon" href="/react-native/img/favicon.png"/><link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.css"/><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/solarized-dark.min.css"/><link rel="alternate" type="application/atom+xml" href="https://facebook.github.io/react-native/blog/atom.xml" title="React Native Blog ATOM Feed"/><link rel="alternate" type="application/rss+xml" href="https://facebook.github.io/react-native/blog/feed.xml" title="React Native Blog RSS Feed"/><script>
|
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
|
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
|
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
|
|
|
ga('create', 'UA-41298772-2', 'auto');
|
|
ga('send', 'pageview');
|
|
</script><script type="text/javascript" src="https://snack.expo.io/embed.js"></script><script type="text/javascript" src="/react-native/js/codeblocks.js"></script><link rel="stylesheet" href="/react-native/css/prism.css"/><link rel="stylesheet" href="/react-native/css/main.css"/><script src="/react-native/js/codetabs.js"></script></head><body class="sideNavVisible"><div class="fixedHeaderContainer"><div class="headerWrapper wrapper"><header><a href="/react-native/"><img class="logo" src="/react-native/img/header_logo.png" alt="React Native"/><h2 class="headerTitleWithLogo">React Native</h2></a><a href="/react-native/versions"><h3>0.59</h3></a><div class="navigationWrapper navigationSlider"><nav class="slidingNav"><ul class="nav-site nav-site-internal"><li class=""><a href="/react-native/docs/getting-started" target="_self">Docs</a></li><li class=""><a href="/react-native/help" target="_self">Community</a></li><li class=""><a href="/react-native/blog/" target="_self">Blog</a></li><li class="navSearchWrapper reactNavSearchWrapper"><input type="text" id="search_input_react" placeholder="Search" title="Search"/></li><li class=""><a href="https://github.com/facebook/react-native" target="_self">GitHub</a></li></ul></nav></div></header></div></div><div class="navPusher"><div class="docMainWrapper wrapper"><div class="container mainContainer"><div class="wrapper"><div class="post"><header class="postHeader"><a class="edit-page-link button" href="https://github.com/facebook/react-native-website/blob/master/docs/understanding-cli.md" target="_blank" rel="noreferrer noopener">Edit</a><h1 class="postHeaderTitle">Understanding the CLI</h1></header><article><div><span><p>Though you may have installed the <code>react-native-cli</code> via npm as a separate module, it is a shell for accessing the CLI embedded in the React Native of each project. Your commands and their effects are dependent on the version of the module of <code>react-native</code> in context of the project. This guide will give a brief overview of the CLI in the module.</p>
|
|
<h1><a class="anchor" aria-hidden="true" id="the-local-cli"></a><a href="#the-local-cli" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>The local CLI</h1>
|
|
<p>React Native has a <a href="https://github.com/facebook/react-native/tree/master/local-cli"><code>local-cli</code></a> folder with a file named <a href="https://github.com/facebook/react-native/blob/master/local-cli/cli.js"><code>cli.js</code></a>. Here, the commands are read from <code>commands.js</code> and added as possible CLI commands. <em>E.G.</em> the <code>react-native link</code> command, exists in the <a href="https://github.com/facebook/react-native/blob/master/local-cli/link/"><code>react-native/local-cli/link</code></a> folder, and is required in <code>commands.js</code>, which will register it as a documented command to be exposed to the CLI.</p>
|
|
<h1><a class="anchor" aria-hidden="true" id="command-definitions"></a><a href="#command-definitions" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Command definitions</h1>
|
|
<p>At the end of each command entry is an export. The export is an object with a function to perform, description of the command, and the command name. The object structure for the <code>link</code> command looks like so:</p>
|
|
<pre><code class="hljs css language-javascript">module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span>
|
|
func<span class="token punctuation">:</span> link<span class="token punctuation">,</span>
|
|
description<span class="token punctuation">:</span> <span class="token string">'links all native dependencies'</span><span class="token punctuation">,</span>
|
|
name<span class="token punctuation">:</span> <span class="token string">'link [packageName]'</span><span class="token punctuation">,</span>
|
|
<span class="token punctuation">}</span><span class="token punctuation">;</span>
|
|
</code></pre>
|
|
<h3><a class="anchor" aria-hidden="true" id="parameters"></a><a href="#parameters" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Parameters</h3>
|
|
<p>The command name identifies the parameters that a command would expect. When the command parameter is surrounded by greater-than, less-than symbols <code>< ></code>, this indicates that the parameter is expected. When a parameter is surrounded by brackets <code>[ ]</code>, this indicates that the parameter is optional.</p>
|
|
<h3><a class="anchor" aria-hidden="true" id="getting-a-list-of-all-cli-commands"></a><a href="#getting-a-list-of-all-cli-commands" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Getting a list of all CLI commands</h3>
|
|
<p>Running <code>react-native --help</code> from inside a React Native project will list all of your current commands. Here is an example from version <code>0.56</code>:</p>
|
|
<pre><code class="hljs css language-sh"> Usage: react-native [options] [<span class="hljs-built_in">command</span>]
|
|
|
|
Options:
|
|
|
|
-V, --version output the version number
|
|
-h, --<span class="hljs-built_in">help</span> 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 <span class="hljs-keyword">for</span> offline use
|
|
unbundle [options] builds javascript as <span class="hljs-string">"unbundle"</span> <span class="hljs-keyword">for</span> 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<span class="hljs-string">'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
|
|
dependencies [options] lists dependencies
|
|
info [options] Get relevant version info about OS, toolchain and libraries
|
|
</span></code></pre>
|
|
<h3><a class="anchor" aria-hidden="true" id="cli-configs"></a><a href="#cli-configs" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>CLI Configs</h3>
|
|
<p>When using <code>react-native start</code>, its platform derivatives, and <code>react-native bundle</code> you can use a file to define the CLI options used by React Native by default. If you create a file <code>rn-cli.config.js</code> in the root of your project, it will be evaluated and options for the commands will come from there.</p>
|
|
<p>You can see the options for the CLI config on the <a href="https://facebook.github.io/metro/docs/en/configuration">metro website</a>. Here's a common <code>rn-cli.config.js</code> used for supporting TypeScript in React Native projects:</p>
|
|
<pre><code class="hljs css language-js">module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span>
|
|
<span class="token function">getTransformModulePath</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|
<span class="token keyword">return</span> require<span class="token punctuation">.</span><span class="token function">resolve</span><span class="token punctuation">(</span><span class="token string">'react-native-typescript-transformer'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
|
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
|
<span class="token function">getSourceExts</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
|
<span class="token keyword">return</span> <span class="token punctuation">[</span><span class="token string">'ts'</span><span class="token punctuation">,</span> <span class="token string">'tsx'</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
|
|
<span class="token punctuation">}</span><span class="token punctuation">,</span>
|
|
<span class="token punctuation">}</span><span class="token punctuation">;</span>
|
|
</code></pre>
|
|
</span></div></article></div><div class="docs-prevnext"></div></div></div></div><footer class="nav-footer" id="footer"><section class="sitemap"><a href="/react-native/" class="nav-home"><img src="/react-native/img/header_logo.png" alt="React Native" width="66" height="58"/></a><div><h5><a href="/react-native/docs/getting-started.html">Docs</a></h5><a href="/react-native/docs/getting-started.html">Getting Started</a><a href="/react-native/docs/tutorial.html">Tutorial</a><a href="/react-native/docs/components-and-apis.html">Components and APIs</a><a href="/react-native/docs/more-resources.html">More Resources</a></div><div><h5>Community</h5><a href="/react-native/help.html">Community Resources</a><a href="/react-native/showcase.html">Who's using React Native?</a><a href="http://stackoverflow.com/questions/tagged/react-native" target="_blank">Stack Overflow</a><a href="https://discord.gg/0ZcbPKXt5bZjGY5n">Reactiflux Chat</a></div><div><h5>More</h5><a href="/react-native/blog">Blog</a><a href="https://twitter.com/reactnative" target="_blank">Twitter</a><a href="https://github.com/facebook/react-native" target="_blank">GitHub</a><a href="http://reactjs.org" target="_blank">React</a></div></section><a href="https://code.facebook.com/projects/" target="_blank" class="fbOpenSource"><img src="/react-native/img/oss_logo.png" alt="Facebook Open Source" width="170" height="45"/></a><section class="copyright">Copyright © 2019 Facebook Inc.</section></footer></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script>window.fbAsyncInit = function() {FB.init({appId:'1677033832619985',xfbml:true,version:'v2.7'});};(function(d, s, id){var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) {return;}js = d.createElement(s); js.id = id;js.src = '//connect.facebook.net/en_US/sdk.js';fjs.parentNode.insertBefore(js, fjs);}(document, 'script','facebook-jssdk'));
|
|
</script><script>window.twttr=(function(d,s, id){var js,fjs=d.getElementsByTagName(s)[0],t=window.twttr||{};if(d.getElementById(id))return t;js=d.createElement(s);js.id=id;js.src='https://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js, fjs);t._e = [];t.ready = function(f) {t._e.push(f);};return t;}(document, 'script', 'twitter-wjs'));</script><script>
|
|
document.addEventListener('keyup', function(e) {
|
|
if (e.target !== document.body) {
|
|
return;
|
|
}
|
|
// keyCode for '/' (slash)
|
|
if (e.keyCode === 191) {
|
|
const search = document.getElementById('search_input_react');
|
|
search && search.focus();
|
|
}
|
|
});
|
|
</script><script>
|
|
var search = docsearch({
|
|
|
|
apiKey: '2c98749b4a1e588efec53b2acec13025',
|
|
indexName: 'react-native-versions',
|
|
inputSelector: '#search_input_react',
|
|
algoliaOptions: {"facetFilters":["tags:0.59"],"hitsPerPage":5}
|
|
});
|
|
</script></body></html> |