If I want to host my gatsby site on somedomain.com
it's necessary to add a CNAME
file with contents
somedomain.com
into public/
.
How can this best be accomplished?
EDIT: related issue... tschaub/gh-pages#34
Your best bet right now is to put it in an assets
folder (or whatever you want to call it) and either manually copy it over to the public
directory or automatically copy it over like @britt is doing here https://github.com/britt/britt.github.com/blob/gatsby/post-build.js#L100
My goal for Gatsby is assets like this would just sit in your pages
directory and automatically get copied over but... there needs to be some changes before that works for CNAME files. Right now this is what happens but it's not ideal as a) you might not want those file types copied and b) what do you do if you want say a CNAME file copied over.
this is my code
"deploy": "gatsby build && cp ./src/CNAME public/ &&gh-pages -d public --branch master"
Even better now: put your CNAME file in the static/
folder and it will be copied untouched at the root or the public/
folder on gatsby build
, ready to be copied to GitHub Pages by gh-pages
@fatuhoku yup! That's been added since — see https://www.gatsbyjs.org/docs/adding-images-fonts-files/#using-the-static-folder
@KyleAMathews the copy part works perfectly fine, thought I noticed (but I could be wrong) that documentation says to put CNAME
into static
. It seems to be thought that it should go into public
: I've also created https://github.com/gatsbyjs/gatsby/pull/8430 for this and described how it was working for me. Hope it is relevant :)
@KyleAMathews the copy part works perfectly fine, thought I noticed (but I could be wrong) that documentation says to put
CNAME
intostatic
. It seems to be thought that it should go intopublic
: I've also created #8430 for this and described how it was working for me. Hope it is relevant :)
As mentioned by @fcatuhe, putting it in the static
folder will copy it to public
as is upon deploy. For anyone stumbling on these threads, and tearing their hair out figuring out why the custom domain is removed, the static
folder works very well.
Most helpful comment
Even better now: put your CNAME file in the
static/
folder and it will be copied untouched at the root or thepublic/
folder ongatsby build
, ready to be copied to GitHub Pages bygh-pages