主题
create-next-app
create-next-app
CLI 允许你使用默认模板或来自公共 GitHub 存储库的 example 创建新的 Next.js 应用。这是开始使用 Next.js 的最简单方法。
¥The create-next-app
CLI allow you to create a new Next.js application using the default template or an example from a public GitHub repository. It is the easiest way to get started with Next.js.
基本用法:
¥Basic usage:
bash
npx create-next-app@latest [project-name] [options]
参考
¥Reference
可以使用以下选项:
¥The following options are available:
选项 | 描述 |
---|---|
-h 或 --help | 显示所有可用选项 |
-v 或 --version | 输发布本号 |
--no-* | 否定默认选项。例如--no-ts |
--ts 或 --typescript | 初始化为 TypeScript 项目(默认) |
--js 或 --javascript | 初始化为 JavaScript 项目 |
--tailwind | 使用 Tailwind CSS 配置初始化(默认) |
--eslint | 使用 ESLint 配置初始化 |
--biome | 使用 Biome 初始化配置 |
--no-linter | 跳过 linter 配置 |
--app | 初始化为 App Router 项目 |
--api | 仅使用路由处理程序初始化项目 |
--src-dir | 在 src/ 目录内初始化 |
--turbopack | 默认情况下,为开发启用 Turbopack |
--import-alias <alias-to-configure> | 指定要使用的导入别名(默认 "@/*") |
--empty | 初始化一个空项目 |
--use-npm | 明确告诉 CLI 使用 npm 引导应用 |
--use-pnpm | 明确告诉 CLI 使用 pnpm 引导应用 |
--use-yarn | 明确告诉 CLI 使用 Yarn 引导应用 |
--use-bun | 明确告诉 CLI 使用 Bun 引导应用 |
-e 或 --example [name] [github-url] | 用于引导应用的示例 |
--example-path <path-to-example> | 单独指定示例的路径 |
--reset-preferences | 明确告诉 CLI 重置任何存储的首选项 |
--skip-install | 明确告诉 CLI 跳过安装包 |
--disable-git | 明确指示 CLI 禁用 git 初始化 |
--yes | 对所有选项使用以前的首选项或默认值 |
示例
¥Examples
使用默认模板
¥With the default template
要使用默认模板创建新应用,请在终端中运行以下命令:
¥To create a new app using the default template, run the following command in your terminal:
bash
npx create-next-app@latest
然后系统会询问你以下提示:
¥You will then be asked the following prompts:
txt
What is your project named? my-app
Would you like to use TypeScript? No / Yes
Which linter would you like to use? ESLint / Biome / None
Would you like to use Tailwind CSS? No / Yes
Would you like your code inside a `src/` directory? No / Yes
Would you like to use App Router? (recommended) No / Yes
Would you like to use Turbopack? (recommended) No / Yes
Would you like to customize the import alias (`@/*` by default)? No / Yes
Linter 选项
¥Linter Options
ESLint:传统且最流行的 JavaScript linter。包含来自 eslint-plugin-next
的 Next.js 特定规则。
¥ESLint: The traditional and most popular JavaScript linter. Includes Next.js-specific rules from eslint-plugin-next
.
Biome:一款快速、现代的 linter 和格式化程序,结合了 ESLint 和 Prettier 的功能。包含内置的 Next.js 和 React 域支持,以实现最佳性能。
¥Biome: A fast, modern linter and formatter that combines the functionality of ESLint and Prettier. Includes built-in Next.js and React domain support for optimal performance.
无:完全跳过 linter 配置。你以后可以随时添加 linter。
¥None: Skip linter configuration entirely. You can always add a linter later.
注意:
next lint
命令将在 Next.js 16 中弃用。新项目应直接使用所选的 linter(例如,biome check
或eslint
)。¥Note:
next lint
command will be deprecated in Next.js 16. New projects should use the chosen linter directly (e.g.,biome check
oreslint
).
回答提示后,将使用你选择的配置创建一个新项目。
¥Once you've answered the prompts, a new project will be created with your chosen configuration.
使用官方 Next.js 示例
¥With an official Next.js example
要使用官方 Next.js 示例创建新应用,请使用 --example
标志。例如:
¥To create a new app using an official Next.js example, use the --example
flag. For example:
bash
npx create-next-app@latest --example [example-name] [your-project-name]
你可以在 Next.js 存储库 中查看所有可用示例的列表以及设置说明。
¥You can view a list of all available examples along with setup instructions in the Next.js repository.
使用任何公开 GitHub 示例
¥With any public GitHub example
要使用任何公共 GitHub 示例创建新应用,请将 --example
选项与 GitHub 存储库的 URL 一起使用。例如:
¥To create a new app using any public GitHub example, use the --example
option with the GitHub repo's URL. For example:
bash
npx create-next-app@latest --example "https://github.com/.../" [your-project-name]