如何直接在当前文件夹中创建 React 应用程序

How to create a React app directly in the current folder

我知道我以前做过,但我似乎无法在任何地方找到答案。我想 运行 create-react-app 而不是在我已经所在的文件夹中创建一个完整的其他文件夹。我相信它只是附加到命令的一个附加标志。

您可以在当前目录中创建一个新的 React 应用程序,只需写入 . 而不是项目名称。

create-react-app .

If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app to ensure that npx always uses the latest version.

对于 create-react-app (v3) 的新版本:

npx create-react-app .

请注意命令末尾的句号(点).对应当前目录

在您所在的当前目录中创建一个文本项目就像 运行 下面的命令一样简单。

npx create-react-app . 

或者当您在全局安装了 create react 应用程序时。

 create-react-app . 

我希望您注意的一件重要事情是每个命令末尾的句号(或句号或圆点)。该句号表示您要在当前文件夹中创建应用程序。

希望对您有所帮助

如果您的当前目录符合 npm 命名限制,以下内容有效。

npx create-react-app . 

当前目录必须:

  • 仅包含 URL 个友好字符
  • 没有大写字母

例如,当前目录不能命名为"React App"。必须是 "react-app".

如果您使用的是最新版本的 Nodejs,那么您可以使用此代码:

npx create-react-app your-app-name

您通过此代码检查 Node 版本:

node --version

v10以上

当您使用 create-react-app app-name 时,create-react-app 之后的部分告诉 CRA where 创建一个反应应用程序。所以 create-react-app app-name 实际上是告诉 CRA 在一个名为 'my-app' 的新目录中创建一个 React 应用程序。对于没有经验的开发人员来说,这可能会导致很多部署问题。

通过使用 npx create-react-app .,我们可以告诉 CRA 在此处或当前目录中创建一个 React 应用程序。这将有助于防止由于没有将 React 应用程序直接放在项目或存储库的根目录中而导致的任何问题。

这个很简单

npx create-react-app .

注意:确保您的文件夹名称以小写开头

你是单纯的类型。而不是 react-app-name

npx create-react-app .

如果您已经有任何以.开头的文件夹名称。那么你会得到一个错误。 您需要删除该文件夹,然后尝试上面的命令

npx create-react-app . my-app --template typescript

创建反应应用程序。

我发现这对于将我的客户端和服务器分离到父项目目录下的单独目录非常有用。通过这种方式,您可以将服务器和客户端分开,并轻松了解哪些 API 正在按预期工作。

这对我有用。

npx create-react-app .

  1. 首先进入你要创建react app的目录
  2. 然后运行命令npx create-react-app .
  • 简单地用点 (.) 代替项目名称。

N.B: 如果你通过这个命令 npm install create-react-app 直接通过 npm 安装 create-react-app 包,那么你必须 运行 以下命令在当前目录 create-react-app . 中创建 react 应用程序(不需要添加然后 npx).

您可以在当前目录中创建一个新的 React 应用程序,只需编写 ./ 而不是项目名称。

运行 您终端中的命令> npx create-react-app ./

例如-

PS E:\React Course\covid-19-state-vice-cases>npx create-react-app ./

就我而言,我使用的是 Windows PowerShell,而 npx create-react-app ./ 对我不起作用,所以我最终改用了这个 -

npx create-react-app .

导航到项目文件,然后使用此命令创建您的应用程序

示例: D:\REACT JS PROJECTS-e-commerce-website> npx create-react-app .