github-pagescnamedocusaurus

Docusaurus CNAME file is deleted after each build


I am building a website with Docusaurus with a custom domain name and hosted with GitHub pages, everything is working fine. But after I run docusaurus-build the CNAME file gets deleted. Causing my website to become unreachable from my custom domain.

What ever I try re-adding the CNAME file does not help it gets deleted after each build.

I understand that docusaurus replaces all the files in the build directory, but how can prevent it from deleting my CNAME file?

My siteConfig file looks like this:

const siteConfig = {
  title: 'Harry Stylesheet' /* title for your website */,
  tagline: 'My Website',
  url: 'http://harrystylesheet.com' /* your website url */,
  baseUrl: '/' /* base url for your project */,

  // Used for publishing and more
  projectName: 'harrystylesheet.github.io',
  organizationName: 'Harry Stylesheet',

    ....
    ....
    ....
}

For now my sollution is to re=configue my GitHub pages settings in my repository, so anyone else running into the same problems?


Solution

  • Docusaurus maintainer here!

    Docusaurus >=2 (update 2021 Nov)

    Add the CNAME file directly into the static folder. Refer to the docs - https://docusaurus.io/docs/deployment#docusaurusconfigjs-settings

    Docusaurus 1

    You're right in saying that everything in build will be generated and you can't add custom files to it. What you can do is to add the cname field to siteConfig.js file as mentioned in the docs here.

    For Docusaurus docs: https://github.com/facebook/Docusaurus/blob/master/v1/website/siteConfig.js#L18

    So for your case, you could add cname: 'harrystylesheet.com' to your siteConfig.js.