create-expo-app

用于创建新 Expo 和 React Native 项目的命令行工具。


create-expo-app 是一个命令行工具,用于创建和设置新的 Expo 和 React Native 项目。该工具通过提供各种模板简化了初始化过程,使用户可以快速开始,而无需手动配置。

创建新项目

🌐 Create a new project

要创建新项目,请运行以下命令:

🌐 To create a new project, run the following command:

Terminal
npx create-expo-app@latest

运行上述命令会提示你输入项目的应用名称。这个应用名称也会在应用配置的 name 属性中使用。

🌐 Running the above command will prompt you to enter the app name of your project. This app name is also used in the app config's name property.

Terminal
What is your app named? my-app

选项

🌐 Options

使用以下选项自定义命令行为。

🌐 Uses the following options to customize the command behavior.

--yes

使用默认选项创建新项目。

🌐 Uses the default options to create a new project.

--no-install

跳过安装 npm 依赖或 CocoaPods。

🌐 Skips installing npm dependencies or CocoaPods.

--template

使用 Node 包管理器 运行 create-expo-app 会初始化并设置一个使用默认模板的新 Expo 项目。

🌐 Running create-expo-app with a Node Package Manager initializes and sets up a new Expo project using the default template.

你可以使用 --template 选项来选择以下模板之一,或者将其作为参数传递给该选项。例如,--template default

🌐 You can use the --template option to select one of the following templates or pass it as an argument to the option. For example, --template default.

信息 想要更多模板?请查看 --example 选项,通过其中的示例应用初始化你的项目,这些示例展示了特定的功能和集成。

TemplateDescription
defaultDefault template. Designed to build multi-screen apps. Includes recommended tools such as Expo CLI, Expo Router library and TypeScript configuration enabled. Suitable for most apps.
blankInstalls minimum required npm dependencies without configuring navigation.
blank-typescriptA Blank template with TypeScript enabled.
tabsInstalls and configures file-based routing with Expo Router and TypeScript enabled.
bare-minimumA Blank template with native directories (android and ios) generated. Runs npx expo prebuild during the setup.

--example

使用此选项可使用来自 expo/examples 的示例初始化项目。

🌐 Use this option to initialize a project using an example from expo/examples.

例如:

🌐 For example:

  • 运行 npx create-expo-app --example with-router 会使用 Expo Router 库设置一个项目
  • 运行 npx create-expo-app --example with-react-navigation 会创建一个类似默认模板的项目,但配置为使用纯 React Navigation 库

--version

打印版本号并退出。

🌐 Prints the version number and exits.

--help

打印可用选项列表并退出。

🌐 Prints the list of available options and exits.

节点包管理器支持

🌐 Node Package Managers support

使用 create-expo-app 创建新项目还会处理为特定的 Node 包管理器设置所需的额外配置。

🌐 Creating a new project with create-expo-app also handles setting up additional configuration needed for a specific Node Package Manager.

如果你正在从一个包管理器迁移到另一个包管理器,你需要在项目中手动进行额外的配置。如果你正在使用 EAS,你还需要手动为项目配置任何额外所需的步骤。

每个包管理器的所有其他步骤都列在下面。

🌐 All the additional steps for each package manager are listed below.

npm

本地安装

🌐 Local installation

npm 是作为 Node.js 安装的一部分安装的。有关安装说明,请参阅 Node.js 文档

🌐 npm is installed as part of Node.js installation. See Node.js documentation for installation instructions.

EAS 安装

🌐 EAS installation

如果项目目录包含 package-lock.json,则默认支持。

🌐 Supported by default if the project directory contains package-lock.json.

Yarn 1(经典)

🌐 Yarn 1 (Classic)

本地安装

🌐 Local installation

Yarn 1(经典版)通常作为 npm 的全局依赖安装。有关安装说明,请参阅 Yarn 1 文档

🌐 Yarn 1 (Classic) is usually installed as a global dependency of npm. See Yarn 1 documentation for installation instructions.

EAS 安装

🌐 EAS installation

如果项目目录包含 yarn.lock,则默认支持。

🌐 Supported by default if the project directory contains yarn.lock.

Yarn 2+ (Modern)

本地安装

🌐 Local installation

请参阅 Yarn 文档 获取安装说明。

🌐 See Yarn documentation for installation instructions.

Yarn 2 及以上版本的包管理方式与 Yarn 1 不同。Yarn 2 及以上版本的核心变化之一是 Plug'n'Play (PnP) 节点链接模型,但它与 React Native 不兼容。

🌐 Yarn 2+ handles package management differently than Yarn 1. One of the core changes in Yarn 2+ is the Plug'n'Play (PnP) node linking model that does not work with React Native.

默认情况下,使用 create-expo-app 和 Yarn 2+ 创建的项目会使用 nodeLinker 并将其值设置为 node-modules 来安装依赖。

🌐 By default, a project created with create-expo-app and Yarn 2+ uses nodeLinker with its value set to node-modules to install dependencies.

.yarnrc.yml
nodeLinker: node-modules

EAS 安装

🌐 EAS installation

在 EAS 上使用 Yarn Modern 需要添加 eas-build-pre-install 钩子。在你项目的 package.json 中,添加以下配置:

🌐 Yarn Modern on EAS requires adding eas-build-pre-install hook. In your project's package.json, add the following configuration:

package.json
{ "scripts": { "eas-build-pre-install": "corepack enable && yarn set version 4" } }

pnpm

本地安装

🌐 Local installation

需要安装 Node.js。请参阅 pnpm 文档 了解安装说明。

🌐 Requires installing Node.js. See pnpm documentation for installation instructions.

默认情况下,使用 create-expo-app 和 pnpm 创建的项目会使用 node-linker,其值设置为 hoisted 来安装依赖。

🌐 By default, a project created with create-expo-app and pnpm uses node-linker with its value set to hoisted to install dependencies.

.npmrc
node-linker=hoisted

信息SDK 54 及更高版本中,Expo 支持隔离安装,如果你更愿意使用隔离依赖,可以删除 node-linker 设置。

EAS 安装

🌐 EAS installation

如果项目目录包含 pnpm-lock.yaml,则默认支持。

🌐 Supported by default if the project directory contains pnpm-lock.yaml.

Bun

有关使用 bun 创建新的 Expo 项目、从其他包管理器迁移以及与 EAS 一起使用的详细信息,请参阅 Bun 指南。

🌐 See Bun guide for details on creating a new Expo project with bun, migration from another package manager, and usage with EAS.