Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deployment resets custom domain when build folder lacks CNAME file #19

Closed
emilkarl opened this issue Sep 23, 2018 · 4 comments
Closed

Comments

@emilkarl
Copy link

Every time I deploy my custom domain on Github for the page is reset to blank? Does anyone have a solution for that?

@ottobonn
Copy link

ottobonn commented Nov 6, 2018

Github reads a file called CNAME in the root directory of the gh-pages branch to set the custom domain. To make the build keep your custom domain, you just need to copy the CNAME file into the build directory.

First, create a file called CNAME in your source code. I put mine in the root directory of my app repository. The contents of the file are your domain:

www.example.com

Now, edit the package.json file, to add one step to the predeploy script:

  "scripts": {
    "predeploy": "npm run build && cp CNAME build/CNAME",
    "deploy": "gh-pages -d build"
  },

Note the addition of the extra step, cp CNAME build/CNAME. This step simply copies your CNAME file into the build directory. When you deploy, your build directory will be the contents of the gh-pages branch, and Github will read the CNAME file to get your custom domain.

@ne-v0y
Copy link

ne-v0y commented Dec 13, 2018

OMG I just got mine fixed and it took me almost a day... for those who have the same issue, in addition to @ottobonn 's solution, don't forget to change your homepage setting to "homepage": "YOUR.CUSTOM.DOMAIN"

jhnferraris added a commit to jhnferraris/jhnferraris.github.io that referenced this issue Mar 3, 2019
@lpshanley
Copy link

lpshanley commented Mar 18, 2019

On a windows machine you may need to use:

"scripts": {
    "predeploy": "npm run build && COPY \"CNAME\" \"./build/CNAME\"",
    "deploy": "gh-pages -d build"
}

@explooosion
Copy link

You can move CNAME into public/.

image

@gitname gitname changed the title Deploy resets custom domain in Github pages Deployment resets custom domain when build folder lacks CNAME file Dec 29, 2019
@gitname gitname closed this as completed Dec 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants