Deployment Gatsby未在github页面上部署工作路径(在url中添加repo名称)
我部署了一个带有Github页面的gatsby网站,我遇到了如下错误: 在本地,一切都能正常工作,错误只发生在服务器上。 服务器似乎无法正确解析路径。 我在域后添加了不必要的存储库名称。如何消除这种情况? 我试图改变一些主机选项并再次部署应用程序,一旦它正常工作,IDK为什么,然后我进行了另一次部署,它再次崩溃。 我的gatsby.config:Deployment Gatsby未在github页面上部署工作路径(在url中添加repo名称),deployment,path,gatsby,github-pages,gatsby-plugin,Deployment,Path,Gatsby,Github Pages,Gatsby Plugin,我部署了一个带有Github页面的gatsby网站,我遇到了如下错误: 在本地,一切都能正常工作,错误只发生在服务器上。 服务器似乎无法正确解析路径。 我在域后添加了不必要的存储库名称。如何消除这种情况? 我试图改变一些主机选项并再次部署应用程序,一旦它正常工作,IDK为什么,然后我进行了另一次部署,它再次崩溃。 我的gatsby.config: const path = require("path"); const { title, keywords, descriptio
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页面时,您需要在build命令中添加一个额外的配置,因为您要添加一个
pathPrefix
变量,您需要允许Netlify如何为这些路径添加前缀。理想情况下,build命令应该如下所示:
"deploy": "gatsby build --prefix-paths && gh-pages -d public"
在您的情况下,由于要添加基于文件的配置(),因此您的构建命令是:
[build]
command = "yarn && yarn testbuild"
publish = "public"
请注意,testbuild
是纱线测试和纱线构建
因此,一种解决方法是将package.json
命令更改为:
"testbuild": "yarn test && yarn build --prefix-paths && gh-pages -d public",
此外,您应该在gh页面分支中,因为它显示:
当您运行npm run deploy
时,公用文件夹的所有内容都将被删除
移动到存储库的gh页面
分支。确保您的
存储库的设置将gh页面
分支设置为
从部署