pathPrefix (documented here) is a helpful feature.
In our case:
//staging (because of reasons)I don't want to add pathPrefix to gatsby-config.js because production doesn't require it. But every time I want to stage, I have to temporarily modify gatsby-config.js to set pathPrefix: "/staging". This upsets source control.
It would be nice if I could just pass the parameter directly (see example, below). That way I don't need to modify gatsby-config.js.
Allow pathPrefix to be passed directly, if not present in gatsby-config.js:
gatsby build --pathPrefix /staging --prefix-paths
Putting pathPrefix in gatsby-config.js is great if it is a permanent setting. But if you only need it sometimes, then it is painful.
This enhancement request is to support the case where you only _sometimes_ want to specify pathPrefix. It will let you easily specify it at runtime as a command line argument.
Hi @robinzimmermann, you can use environment variables to pass th e pathPrefix value.
Your staging environment build script:
PATH_PREFIX='/staging' gatsby build --prefix-paths
Your production environment build script:
gatsby build
In gatsby-config.js:
module.exports = {
pathPrefix: process.env.PATH_PREFIX || ""
// rest of the configuration
}
This way you can specify the pathPrefix at runtime as a command line argument and won't need to modify gatsby-config.js to set it.
Sadly, i got this error
ValidationError: child "pathPrefix" fails because ["pathPrefix" is not allowed to be empty]
So, I had to change my config to this
module.exports = {
pathPrefix: process.env.PATH_PREFIX || "/"
// rest of the configuration
}
;D
Most helpful comment
Hi @robinzimmermann, you can use environment variables to pass th e
pathPrefixvalue.Your staging environment build script:
PATH_PREFIX='/staging' gatsby build --prefix-pathsYour production environment build script:
gatsby buildIn
gatsby-config.js:This way you can specify the
pathPrefixat runtime as a command line argument and won't need to modifygatsby-config.jsto set it.