问题描述
我部署了一个带有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,},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`,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 Pages时,由于要添加pathPrefix
变量,因此需要在构建命令中添加额外的配置,因此需要允许Netlify如何为这些路径添加前缀。理想情况下,build命令应如下所示:
"deploy": "gatsby build --prefix-paths && gh-pages -d public"
在您的情况下,由于要添加基于文件的配置(netlify.toml
),因此您的构建命令为:
[build]
command = "yarn && yarn testbuild"
publish = "public"
请注意,testbuild
是yarn test && yarn build
,according to your repository。
因此,一种解决方法是将您的package.json
命令更改为:
"testbuild": "yarn test && yarn build --prefix-paths && gh-pages -d public",
此外,您应该在gh-pages
分支中,因为它显示了Gatsby's documentation:
运行
npm run deploy
时,公用文件夹的所有内容都将 已移至存储库的gh-pages
分支。确保您的 存储库的设置将gh-pages
分支设置为 部署。