Gatsby: Way to use "build --prefix-paths" with more than 1 choice?

Created on 13 Nov 2019  路  6Comments  路  Source: gatsbyjs/gatsby

Summary

For GH pages deploy/build I need the path prefix to be like /foo/bar/
However for my production deploy I need the path prefix to be like /some/thing/

Is there a way I can set more than one path prefix and then on each npm build script say which prefix to use? Or, is there a way to dynamically pass the prefix to use to the build command? like build --prefix-paths "/my/prefix/" ?

Or am I just SOL?

question or discussion

Most helpful comment

Yes env vars are the way to go. You can use dotenv to have multiple .env files depending what your using or just integrate it in your npm scripts like PREFIX=/foo/bar gatsby build

in your gatsby-config.js

module.exports = {
  pathPrefix: process.env.PREFIX
}

Thank you for opening this, @ecumike

We're marking this issue as answered and closing it for now but please feel free to reopen this and comment if you would like to continue this discussion. We hope we managed to help and thank you for using Gatsby! 馃挏

All 6 comments

Interesting question. I don't know about your set-up but if deploying to production on Netlify I could theoretically get the value of 'pathPrefix' in gatsby-config.js from my environment variables. I haven't tested this, though! Have you tried it?

I'm going straight from Github Enterprise to CF cloud app. I don't use Netlify or anything. The webhook runs my build stage which simply runs npm install && npm run build and then fires up nginx and done.

Being able to set it as an env variable would work well as that's how other stuff usually works, allowing for environment-specific settings. So I guess that's really the ask: A way to specific a path-prefix for one env and a different one for another.

Yes env vars are the way to go. You can use dotenv to have multiple .env files depending what your using or just integrate it in your npm scripts like PREFIX=/foo/bar gatsby build

in your gatsby-config.js

module.exports = {
  pathPrefix: process.env.PREFIX
}

Thank you for opening this, @ecumike

We're marking this issue as answered and closing it for now but please feel free to reopen this and comment if you would like to continue this discussion. We hope we managed to help and thank you for using Gatsby! 馃挏

AHH yes.. I forgot about simply setting/using env var like that. Perfect, thanks!

Sorry for reviving the dead thread. Does Gatsby support relative path prefix? If it does, it would implicitly support isomorphic deployment across different prefixes.
FYI, Create-React-App supports it by simply setting the homepage field to "." in the package.json.

Was this page helpful?
0 / 5 - 0 ratings