部署gatsby站点以使用--prefix-paths进行Netlify [英] Deploy gatsby site to netlify with --prefix-paths
问题描述
我正在尝试将一个用Gatsby构建的博客站点部署到Netlify.问题是,我想从/blog服务该站点. 遵循文档之后,我将gatsby-config.js更改为包含pathPrefix,如下所示:
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: [...]
}
接下来,我将构建命令更改为包括--prefix-paths:
Next, I changed my build command to include --prefix-paths:
gatsby build --prefix-paths
当我使用gatsby serve --prefix-paths
在本地运行站点时,一切正常.但是,在我部署netlify之后,该站点仍然是由root/而不是/blog提供的.
我的netlify.toml:
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"
构建命令frum netlify.toml从package.json运行以下命令:
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",
我在这里想念什么?我是否需要进行其他配置以进行netlify或其他功能?
What am I missing here? Do I need to make some other configuration to netlify or something?
推荐答案
适用于遇到相同问题的任何人.我可以通过将公用文件夹内的所有文件复制到"blog"文件夹中来解决此问题,如下所示:
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"
我将move命令添加到package.json,并在构建后执行它.我不确定这是否是我应该做的方式,但是在进行了一些研究(我还发现一个开始这样做的人)之后,我认为还可以.
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.
现在,文件是通过"/blog"提供的,一切正常.
Now that the files are served from "/blog" everything works fine.
这篇关于部署gatsby站点以使用--prefix-paths进行Netlify的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!