Recently, GitHub Pages added an option to publish from master, gh-pages, or a /docs folder on your master branch. It would be nice to have the option to output built files to a /docs directory and skip the gh-pages step altogether.
A sketch of what this might look like is here: https://github.com/rileyjshaw/gatsby/commit/7136388cb4c302da488fa4e755e69854e6de8a40
I haven't bothered testing it yet — I'll wait to hear back before I clean things up. I'm setting the default to 'public' on a per-use basis, which is a total hack. Any suggestions on where I should set defaults for config.toml values?
We've discussed here making the output directory configurable before but no one has ever cared enough to take it on.
I'm not 100% convinced it's a good idea though. For your particular use case — deploying to Github Pages — there's the gh-pages npm module which makes it trivial to deploy to the gh-pages branch. In fact all the starters have this built in so you can run npm run deploy and your site is live.
Also the code Gatsby outputs would make for messy diffs if you had to check it in on the master branch. I've checked in compiled code before in the past and really disliked it. It's not a pattern I'd encourage Gatsby users follow.
So... making the output directory configurable is feeling a bit YAGNI to me :-) Is using the gh-pages npm module an acceptable compromise?
I'm familiar with the gh-pages module; I've used it a bunch on past projects. It's great for a lot of use-cases, and totally makes sense as the default on starter projects! For the current site I'm building I need to keep the source and build on the same branch, though :/
re: messy diffs, splitting things up into source-only commits and build-only releases won't be a problem for me. Again, the strong default can be "check in compiled code on a separate branch", but it'd be nice for folks to have the option if a hardcoded public folder doesn't work for them.
I could easily extend things on my project to just mv public $(outDir) on each build… but I think exposing this through config makes sense :)
I'm more of a convention/code > configuration kind of programmer. Especially as a maintainer, the more configuration, the more code to be maintained and complexity to be dealt with when considering new features. Also the more configuration there is the "heavier" the framework seems to people. Most people adopting Gatsby comment how "simple" it is and I'd really like to keep it that way.
I really like the React/Hapi.js models of defining core abstractions/primitives and then giving you ways to compose these primitives as well as lifecycle hooks to reach in as necessary.
Speaking of lifecycle hooks, have you run across postBuild yet? :-) https://github.com/gatsbyjs/gatsby#perform-additional-post-build-step
Let's leave this open for other people to weigh in but since you (and others with the same problem) can solve this with 1-2 lines of code, I don't think it should be a core concern.
Fair enough!
postBuild seems interesting - do you have a suggestion on how I should use it to relocate public/ to docs/?
If you export a "postBuild" function, this gets called once your build
completes. So there you'd use the node fs APIs to move public/ to docs/
On Sun, Nov 20, 2016 at 2:26 PM Riley Shaw [email protected] wrote:
Fair enough!
postBuild seems interesting - do you have a suggestion on how I should
use it to relocate public/ to docs/?—
You are receiving this because you commented.Reply to this email directly, view it on GitHub
https://github.com/gatsbyjs/gatsby/issues/562#issuecomment-261806991,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEVh54Bph-qOdWpqfj0Dx2jPPYCIYOMks5rALrxgaJpZM4K2LNt
.
For anyone else who visits, this can easily be done by adding the below snippet to gatsby-node.js. You can use whatever you want to copy the folder, I just like how simple cp is.
import Shell from 'child_process'
function postBuild(pages, callback) {
Shell.execSync("cp -R public docs/")
callback()
}
export { postBuild }
Closing this as it's not a desired feature.
Hey @vinnymac, great little solution. I was looking to do the same thing as you, @rileyjshaw.
I did run into a transpilation error:

that was fixed by yarn add babel-preset-es2015. It's likely there is a cleaner solution to this but I just wanted to drop this here in case anyone runs into the same problem I did.
... well, this is embarrassing. It seems not to have fixed things. Any advice on how I'd go about actually doing that?
🐑
Most helpful comment
For anyone else who visits, this can easily be done by adding the below snippet to
gatsby-node.js. You can use whatever you want to copy the folder, I just like how simplecpis.