Skip to content

Latest commit

 

History

History
124 lines (85 loc) · 4.27 KB

commands.md

File metadata and controls

124 lines (85 loc) · 4.27 KB

Commands

React Native CLI comes with following commands:

init

Available since 0.60.0

IMPORTANT: Please note that this command is not available through react-native-cli, hence you need to either invoke it directly from the @react-native-community/cli package which proxies binary to this CLI since 0.60.0, so it's possible to use it with e.g. npx.

Usage (with npx):

npx react-native@latest init <projectName> [options]

Initialize a new React Native project named in a directory of the same name. You can find out more use cases in init docs.

Options

--version <string>

The version of React Native to use with the template.

--directory <string>

Uses a custom directory instead of <projectName>.

--title <string>

Uses a custom app title instead of <projectName>.

--template <string>

Uses a custom template. Accepts following template sources:

  • an npm package name
  • an absolute path to a local directory
  • an absolute path to a tarball created using npm pack
  • link to a GitHub repository (supports username/repo format)

Example:

npx react-native-community/cli@latest init MyApp --template react-native-community/cli-custom-template
npx react-native-community/cli@latest init MyApp --template file:///Users/name/template-path
npx react-native-community/cli@latest init MyApp --template file:///Users/name/template-name-1.0.0.tgz
npx react-native-community/cli@latest init MyApp --template Esemesek/react-native-community/cli-new-template
# Use a specific version of the community template with the nightly release of React Native
npx react-native-community/cli@latest init MyApp --template @react-native-community/template0.74.0 --version nightly

A template is any directory or npm package that contains a template.config.js file in the root with the following type:

type Template = {
  // Placeholder used to rename and replace in files
  // package.json, index.json, android/, ios/
  placeholderName: string;
  // Directory with template
  templateDir: string;
  // Path to script, which will be executed after init
  postInitScript?: string;
  // Placeholder used to rename app title inside values.xml and Info.plist
  titlePlaceholder?: string;
};

Example template.config.js:

module.exports = {
  placeholderName: 'ProjectName',
  titlePlaceholder: 'Project Display Name',
  templateDir: './template',
  postInitScript: './script.js',
};

--skip-install

Skip dependencies installation

--install-pods [boolean]

Determine if CocoaPods should be installed when initializing a project. If set to true it will install pods, if set to false, it will skip the step entirely. If not used, prompt will be displayed

--pm <string>

Use specific package manager to initialize the project. Available options: yarn, npm, bun. Default: yarn

--package-name <string>

Create project with custom package name for Android and bundle identifier for iOS. The correct package name should:

  • contain at least two segments separated by dots, e.g. com.example
  • contain only alphanumeric characters and dots

--skip-git-init <boolean>

Skip git repository initialization.

--replace-directory <string>

Replaces the directory if it already exists

--yarn-config-options <string>

Passes extra options that will be added to .yarnrc.yml file, format: key=value,key2=value2.