0

我用 Github 页面部署了一个 gatsby 网站,但我遇到了这样的错误: 在此处输入图像描述 本地一切正常,错误只发生在服务器上。似乎服务器无法正确解析路径。我在域之后添加了不必要的存储库名称。如何删除它?我尝试更改一些主机选项并再次部署应用程序,一旦它正常工作,IDK 为什么,然后我进行了另一个部署,它再次崩溃。我的 gatsby.config:

const path = require("path");
const { title, keywords, description, author, defaultLang, trackingId } = require("./config/site");

module.exports = {
  pathPrefix: "/lbearthworks",
  siteMetadata: {
    title,
    keywords,
    description,
    author,
  },
  plugins: [
    {
      resolve: "gatsby-plugin-google-analytics",
      options: {
        trackingId,
      },
    },
    {
      resolve: "gatsby-plugin-manifest",
      options: {
        name: title,
        short_name: "Lb",
        start_url: "/",
        background_color: "#212121",
        theme_color: "#fed136",
        display: "minimal-ui",
        icon: "content/assets/gatsby-icon.png",
      },
    },
    "gatsby-transformer-remark",
    {
      resolve: "gatsby-source-filesystem",
      options: {
        name: "markdown",
        path: `${__dirname}/content`,
      },
    },
    {
      resolve: "gatsby-source-filesystem",
      options: {
        name: "images",
        path: `${__dirname}/content/assets/images`,
      },
    },
    "gatsby-plugin-eslint",
    "gatsby-plugin-react-helmet",
    "gatsby-transformer-sharp",
    "gatsby-plugin-sharp",
    "gatsby-plugin-offline",
    {
      resolve: "gatsby-plugin-sass",
      options: {
        data: `@import "core.scss";`,
        includePaths: [path.resolve(__dirname, "src/style")],
      },
    },
    ...
  ],
};

现场版

Github 存储库

4

1 回答 1

0

在处理 GitHub Pages 时,您需要在构建命令中添加额外的配置,因为您正在添加pathPrefix变量,因此您需要允许 Netlify 如何为这些路径添加前缀。理想情况下,构建命令应如下所示:

"deploy": "gatsby build --prefix-paths && gh-pages -d public"

在您的情况下,因为您要添加基于文件的配置 ( netlify.toml),所以您的构建命令是:

[build]
  command = "yarn && yarn testbuild"
  publish = "public"

请注意,根据您的存储testbuild库。yarn test && yarn build

因此,一种解决方法是将您的package.json命令更改为:

"testbuild": "yarn test && yarn build --prefix-paths && gh-pages -d public",

此外,您应该在gh-pages分支中,因为它显示了Gatsby 的文档

当您运行npm run deploy公用文件夹的所有内容时,将被移动到您的存储库的gh-pages分支。确保您的存储库的设置将gh-pages分支设置为要部署的源。

于 2020-10-12T07:23:57.070 回答