pathPrefix in gatsby-config is not prepending the prefix to assets.
See original GitHub issueHello everyone. I’m trying to deploy my gatsby project on a sub-directory like: https://www.example.com/blog
Following the docs, I added a /blog
path prefix into my gatsby-config.js
file. Then, I build the project using the command gatsby build --prefix-paths
When i check my generated index.html
in my public
folder, i’m seeing that the prefix is not prepended to the statics assets’ path.
I’ve started from a fresh project and yet I am still having the issue. Maybe I’ve been looking at it for too long and missing something stupid. I’ve also tried double quotes, simple quotes, removing the leading slash, but nothing seems to work. Any help would be appreciated.
Steps to reproduce
- Start a new project :
gatsby new gatsby-site
- Add a pathPrefix into
gatsby-config.js
:
siteMetadata: {
pathPrefix: `/blog`,
},
- Build the project using the flag :
gatsby build --prefix-paths
- Check the presence of the prefix you chose in the assets linked in the
index.html
file
Expected result
Linked static assets prepended with the path prefix should be like :
src="/blog/static/6d91c86c0fde632ba4cd01062fd9ccfa/630fb/gatsby-astronaut.png"
Actual result
src="/static/6d91c86c0fde632ba4cd01062fd9ccfa/630fb/gatsby-astronaut.png"
Environment
System: OS: Windows 10 10.0.18362 CPU: (4) x64 Intel® Core™ i5-6600K CPU @ 3.50GHz Binaries: Node: 12.5.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD Languages: Python: 2.7.16 - /c/Python27/python Browsers: Edge: 44.18362.449.0 npmPackages: gatsby: ^2.21.37 => 2.21.37 gatsby-image: ^2.4.4 => 2.4.4 gatsby-plugin-manifest: ^2.4.5 => 2.4.5 gatsby-plugin-offline: ^3.2.3 => 3.2.3 gatsby-plugin-react-helmet: ^3.3.1 => 3.3.1 gatsby-plugin-sharp: ^2.6.4 => 2.6.4 gatsby-source-filesystem: ^2.3.4 => 2.3.4 gatsby-transformer-sharp: ^2.5.2 => 2.5.2 npmGlobalPackages: gatsby-cli: 2.11.8
gatsby-config.js
module.exports = {
siteMetadata: {
pathPrefix: `/blog`,
title: `Gatsby Default Starter`,
description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
author: `@gatsbyjs`,
},
plugins: [
`gatsby-plugin-react-helmet`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
resolve: `gatsby-plugin-manifest`,
options: {
name: `gatsby-starter-default`,
short_name: `starter`,
start_url: `.`,
background_color: `#663399`,
theme_color: `#663399`,
display: `minimal-ui`,
icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
},
},
// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.dev/offline
// `gatsby-plugin-offline`,
],
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Hi @RebootGG
Could you try moving your
pathPrefix: '/blog',
from thesiteMetadata
to 1 level up and see if that works, the docs say it needs to be in the root level of the object put inmodule.exports
for it to work@LekoArts This needs to be documented here: