简体   繁体   English

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

[英]Create Gatsby Project on a git initialized folder

I have a git folder with no files, so i wanted to use the Gatsby CLI to create a project in that folder.我有一个没有文件的 git 文件夹,所以我想使用 Gatsby CLI 在该文件夹中创建一个项目。 Using gatsby new .使用gatsby new . but failed that the repository is not empty but it only have .git folder only.但失败的是存储库不是空的,但它只有.git文件夹。 What alternatives can i use to achieve my objective.我可以使用哪些替代方案来实现我的目标。

With gatsby new .随着gatsby new . you are setting the name of your project and the starter you want to clone (by default this one ), in your case, it is an invalid syntax because you are setting neither the name nor the starter so it fails.您正在设置项目的名称和要克隆的启动器(默认情况下是这个),在您的情况下,这是一种无效的语法,因为您既没有设置名称也没有设置启动器,因此它失败了。

From Gatsby docs :来自盖茨比文档

There are many Enterprise level companies that maintain an internal clone of the NPM registry for security purposes.出于安全目的,有许多企业级公司维护 NPM 注册表的内部克隆。 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 .如果您在这样的公司工作,您可能会发现您可以成功运行npm install -g gatsby-cli无法运行 gatsby new,因为 gatsby new 命令从公共 GitHub存储库克隆了一个 repo Many companies block public GitHub, which will cause the gatsby new command to fail.很多公司屏蔽了公共 GitHub,这会导致 gatsby new 命令失败。 Not to worry, though, you can set up a new Gatsby site without the gatsby new command with a few quick steps.不过不用担心,您可以通过几个快速步骤在没有 gatsby new 命令的情况下设置一个新的 Gatsby 站点。

One easy thing you can do is to create your new project using gatsby-cli (like gatsby new test-project) , cut all content, and paste it to your desired folder which is linked via .git folder to your repository.您可以做的一件简单的事情是使用gatsby-cli创建您的新项目(如gatsby new test-project) ,剪切所有内容,并将其粘贴到您想要的文件夹中,该文件夹通过.git文件夹链接到您的存储库。

Alternatively, you can create your project normally ( gatsby new test-project ) and then start your git ( git init ) and link it to your repository using:或者,您可以正常创建您的项目 ( gatsby new test-project ),然后启动您的 git ( git init ) 并使用以下命令将其链接到您的存储库:

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

More information about adding a remote here .有关在此处添加遥控器的更多信息。

Another option is to create a gatsby project without using the new keyword.另一种选择是在不使用new关键字的情况下创建 gatsby 项目。 For that, in your desired project directory:为此,在您想要的项目目录中:

  • You will have to create an initialized package.json file by running npm init -y您必须通过运行npm init -y创建一个初始化的package.json文件
  • then npm install gatsby react react-dom然后npm install gatsby react react-dom
  • then create a index.js file in src/pages directory然后在src/pages目录下创建一个index.js文件
  • run gatsby develop运行gatsby develop

Now you have a gatsby development server up and running.现在您已经启动并运行了 gatsby 开发服务器。 In this way, you may not have all the configuration that comes with the starter project.这样,您可能没有启动项目附带的所有配置。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM