Deploy gatsby site to netlify with --prefix-paths

删除回忆录丶 提交于 2020-03-23 23:51:42

问题


I'm trying to deploy a blog site built with Gatsby to Netlify. The thing is, I want to serve the site from /blog. Following the docs, I changed the gatsby-config.js to include pathPrefix like so:

module.exports = {
  pathPrefix: `/blog`,
  siteMetadata: {...},
  plugins: [...]
}

Next, I changed my build command to include --prefix-paths:

gatsby build --prefix-paths

When I run the site locally using gatsby serve --prefix-paths everything works fine. However, after I deployed to netlify the site is still being served from root / and not from /blog. My netlify.toml:

[build]
  Command = "npm run build"
  Functions = "lambda"
  Publish = "public"

The build command frum netlify.toml runs the command from package.json which is this:

"build": "run-p build:**",
"build:app": "gatsby build --prefix-paths",
"build:lambda": "netlify-lambda build src/lambda",

What am I missing here? Do I need to make some other configuration to netlify or something?


回答1:


For anyone encountering the same issue. I was able to solve this by copying all the files inside the public folder into the "blog" folder like so:

"build": "run-p build:**",
"build:app": "npm run clean && gatsby build --prefix-paths && npm run move",
"build:lambda": "netlify-lambda build src/lambda",
"move": "cd public && mkdir blog | mv * blog"

I added the move command to package.json and I execute it after the build. I'm not sure if that's how I'm suppose to do it but after doing some research (I also found a started that was doing this) I think it's ok.

Now that the files are served from "/blog" everything works fine.



来源:https://stackoverflow.com/questions/56425441/deploy-gatsby-site-to-netlify-with-prefix-paths

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!