【问题标题】:Netlify fails to deploy site after public is added to .gitignore将公共添加到 .gitignore 后,Netlify 无法部署站点
【发布时间】:2018-11-17 21:54:48
【问题描述】:

我正在尝试遵循 Blogdown 书中的建议。有一段时间,我在本地构建我的 blogdown 站点,然后让 Netlify 部署它。

我现在读到我可以将我的 public/ 文件夹添加到 .gitignore,因为 Hugo 应该在远程服务器上构建它:

如果您的网站要在 Netlify 等远程服务器上自动(重新)构建,则应忽略 public/ 目录。

所以,我试过了。我确保 GitHub 不再跟踪 public/ 了。 我所做的是这个。

首先,我将public 添加到我的.gitignore 然后,我有了这个 git commit

git rm -r --cached .
git add .
git commit -am "Remove ignored files"

正如预期的那样,这从 GitHub (https://github.com/taraskaduk/taraskaduk) 中删除了我的 public/ 文件夹。

在 Netlify 上,我的部署失败。 首先,这是我的部署设置(我觉得我应该在这里更改一些内容,但我没有看到任何这样做的说明):

Repository: https://github.com/taraskaduk/taraskaduk
Build command: Not set
Publish directory: public
Production branch: master
Branch deploys: Deploy only the production branch and its deploy previews
Public deploy logs: Logs are public

(我尝试弄乱发布目录和构建命令,但没有说明,这是浪费时间,因为我不确定自己在做什么)

现在,这是部署日志

5:18:42 PM: Build ready to start
5:18:44 PM: Fetching cached dependencies
5:18:44 PM: Starting to download cache of 131.5MB
5:18:45 PM: Finished downloading cache in 1.239616218s
5:18:45 PM: Starting to extract cache
5:18:46 PM: Finished extracting cache in 1.126354925s
5:18:46 PM: Finished fetching cache in 2.450276606s
5:18:46 PM: Starting to prepare the repo for build
5:18:47 PM: Preparing Git Reference refs/heads/master
5:18:47 PM: No build command found, continuing to publishing
5:18:47 PM: Failing build: Failed to build site
5:18:47 PM: failed during stage 'building site': Deploy directory 'public' does not exist
5:18:48 PM: Finished processing build request in 4.119821718s

我想我不清楚的是,如果它应该被重建,它为什么要寻找公共目录?

我想有些东西对我来说没有点击...我确定我的错误是相当愚蠢和基本的。帮忙?


编辑: 按照下面的建议,我添加了一个构建命令和雨果版本。现在部署没有失败,Netlify 说该站点是活动的,但 URL 上没有任何内容

【问题讨论】:

  • 我不确定这是否有帮助,但我的 blogdown 网站在 netlify 的“构建命令”中都有一些版本的“hugo”。我的年长者使用“hugo_0.19”,而我最近的一个使用“hugo”,因为我 manually set the version of Hugo 使用比 0.19 更新的东西。
  • 半工作。现在,部署不会失败。但是,该网站本身并不是实时的(尽管 Netlify 说它是实时的)。我收到一个错误...

标签: r hugo blogdown netlify


【解决方案1】:

一旦您的.gitignore 正常工作,将netlify.toml 添加到您的站点项目将有助于确保正确的构建命令也可以与您针对部署上下文的目标版本一起运行。

# Global settings applied to the whole site.
[build]
  command = "hugo"
  publish = "public"

# Build a preview of the site (Drafts and Future dates also) 
#   Un-comment next two lines.
#[context.deploy-preview]
#  command = "hugo --buildFuture"

[context.production.environment]
  HUGO_VERSION = "0.41"

# you can lock a version of hugo for a deploy preview
[context.deploy-preview.environment]
  HUGO_VERSION = "0.41"

# you can lock a version of hugo for a branch-deploy (other than previews)
[context.branch-deploy.environment]
  HUGO_VERSION = "0.41"

这将允许您更好地控制您的构建。

注意: More information here also

【讨论】:

    【解决方案2】:

    cmets 中提出了解决方案(至少是部分的):我错过了 hugo 部署命令

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-20
      • 2020-05-24
      相关资源
      最近更新 更多