I go into the page in Github (https://github.com/user/repo/settings/pages) and set a custom domain. It works great!
However, every time I deploy (using the gh-pages npm package) it resets the domain back to
https://user.github.io/repo
This is incredibly frustrating... how can I tell it to use my custom domain permanently?
It looks like there are reports about this in the repo for gh-pages npm package. See #347, #236, #370, #213.
There is even a still opened merged pull-request that tackles the issue through documentation.
Basically, it says:
Modify the deployment line to your deploy script if you use custom domain. This will prevent deployment to remove the domain from settings in github.
echo 'your_cutom_domain.online' > ./build/CNAME && gh-pages -d build"
Edit: there are other options as well, some people directly change their deployment call and add a custom domain to their deployment scritpt:
var ghpages = require('gh-pages');
var fs = require('fs');
fs.writeFile('dist/CNAME', "your-custom-domain.com", function(err) {});
ghpages.publish('dist', function(err) {});
others just follow the advice for putting CNAME to your publishing folder.
For my React static site I have to add below scripts to the package.json to add the CNAME file with the custom domain to the build/ dir before each deployment.
"scripts": {
"build": "react-scripts build",
"add-domain": "echo \"myAwesomeDomain.org\" > build/CNAME",
"deploy": "npm run add-domain && gh-pages -d build",
"bd": "npm run build && npm run deploy",
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With