在 git 个初始化文件夹上创建 Gatsby 项目

Create Gatsby Project on a git initialized folder

我有一个没有文件的 git 文件夹,所以我想使用 Gatsby CLI 在该文件夹中创建一个项目。 使用 gatsby new . 但失败,因为存储库不是空的,但它只有 .git 文件夹。 我可以使用哪些替代方案来实现我的 objective.

使用 gatsby new . 设置项目名称和要克隆的启动器(默认情况下 this one),在您的情况下,这是一个无效语法,因为您既没有设置名字和启动器所以它失败了。

来自 Gatsby docs:

There are many Enterprise level companies that maintain an internal clone of the NPM registry for security purposes. If you work for such a company, you may find that you are able to successfully run npm install -g gatsby-cli but cannot run the gatsby new as the gatsby new command clones a repo from a public GitHub repository. Many companies block public GitHub, which will cause the gatsby new command to fail. Not to worry, though, you can set up a new Gatsby site without the gatsby new command with a few quick steps.

您可以做的一件简单的事情是使用 gatsby-cli 创建您的新项目(如 gatsby new test-project),剪切所有内容,然后将其粘贴到您想要的 link 文件夹通过 .git 文件夹到您的存储库。

或者,您可以正常创建您的项目 (gatsby new test-project),然后启动您的 git (git init) 并将其 link 到您的存储库,使用:

git remote add origin remote <repositoryURL>
git add .
git commit -m "Initial commit"
git push -f origin master

有关添加遥控器的详细信息here

另一种选择是不使用 new 关键字创建 gatsby 项目。为此,在您想要的项目目录中:

  • 您必须通过 运行ning npm init -y
  • 创建一个初始化的 package.json 文件
  • 然后 npm install gatsby react react-dom
  • 然后在src/pages目录下创建一个index.js文件
  • 运行 gatsby develop

现在您已经启动并 运行ning 了一个 gatsby 开发服务器。这样一来,你可能还没有启动项目自带的所有配置。

更多信息:https://www.gatsbyjs.com/docs/setting-up-gatsby-without-gatsby-new/