gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.3k stars 10.31k forks source link

different build / serve directories #14270

Closed dwehrmann closed 5 years ago

dwehrmann commented 5 years ago

I was wondering whether it is possible to have a custom output folder for gatsby build and gatsby serve.

Here's my use case: We have a gatsby site deployed on a root server (netlify can not be used for our project) via gatsby serve. We have decided against webhooks, instead the site is re-built every hour via cronjob. Whenever the new build process starts, gatsby wipes its public folder, thus leaving the site non-accessible for visitors. It takes roughly 12 minutes for the build process to finish during which the sites appears "offline" for visitors. Makes roughly 2,5 hrs. downtime a day which is not acceptable of course.

I was looking for a way to have a different build output folder and another serve folder so that I can have the site built and after a successful build copy over the new contents into the served folder but that currently seems not possible with gatsby – am I correct?

I'd be happy to hear what the best approach would be.

LekoArts commented 5 years ago

You shouldn't use gatsby serve in production, it's only for testing purposes. Please use a webserver like nginx! Most people (also Netlify does that afaik) build their site in another directory and then copy over the files to the www of the webserver.

Please let us know if you need further help with that, thanks!

dwehrmann commented 5 years ago

@LekoArts Hmm okay thanks, I understand. Nginx only serves me a list of all the files in the public directory, not the actual website – but I recognize that would be a nginx config issue on my side. Just out of curiosity, where are the downsides with gatsby serve? I am running it with pm2 and it works pretty well so far, nginx currently does the reverse proxy.

Yes, I have gone exactly the path you described, building in one gatsby directory and then rsyncing the files over into the other gatsby/public directory that is served by gatsby serve. Swapping gatsby serve for Nginx would of course allow me to trash the second gatsby installation which makes sense. I will have to look into the nginx config issue then. Thank you!