Next.js: Deploying static site to GitHub pages needs .nojekyll file

Created on 20 May 2017  路  13Comments  路  Source: vercel/next.js

Something I noticed deploying to GitHub pages is that the _next folder is by default not served by GitHub (404s) as mentioned here (underscored folders are ignored): https://github.com/blog/572-bypassing-jekyll-on-github-pages

Would it be possible for the _next folder to not begin with an underscore, or instead to add a note to the README mentioning this behaviour and the fact you need to add a blank .nojekyll file to the out dir otherwise?

All 13 comments

@benhjames I think we should go with _next. But I'd like for such a note on on the README.
Could you send me a PR.
May be create a Wiki and add instruction to it. Then let's link that.

@arunoda @benhjames having a problem with github pages.

  1. if .nojekyll is in out directory, github pages does not serve the default index.html file. I added one to the root of my project as well and it seemed to make it work. (I have .nojekyll in both out and root)
  2. Even still i get network request rejected by github pages for the _next files.

https://conciergeauctions.github.io/styled-material-components/

https://github.com/ConciergeAuctions/styled-material-components

@brad-decker I believe the best way to serve it is through a gh-pages branch with just the contents of the out directory (also with .nojekyll)

See how I do it here! https://github.com/benhjames/benjames.me/

And better instructions here: https://gist.github.com/cobyism/4730490

@benhjames the actual issue here is https://github.com/jekyll/jekyll/issues/332 this ... it looks like _config.yml can set the base path for the site, however if we have a .nojekyll file does that mean that it'll ignore _config.yml? Is there a next.js way to set a base path?

Having the out dir hosted in a branch gets around that since the base path of the site is the root of the branch.

I don't think there's currently support for exporting a site that you want to host within a folder, but I may well be wrong!

@benhjames the base path for my site is https://conciergeauctions.github.io/styled-material-components/

the paths added for the build are relative urls that hit /_next/

that would resolve to https://conciergeauctions.github.io/_next/ not https://conciergeauctions.github.io/styled-material-components/_next/

Am i doing something wrong with my export setup? @benhjames @arunoda

@benhjames your site works due to custom cname/domain

Which i suppose is a totally fine workaround if nothing else works :P

Ahhh sorry I see, I assumed it was a GitHub user page rather than a project page! Yeah I can't really see a way to make that work right now other than via custom domain...!

Do you think a configuration option for custom root path url would be something usable? that would get appended ahead of /_next/ and static resources inside the index.html file?

Yeah I can see that being useful - @arunoda what do you think? Then you could host a static site with its root at e.g. https://mycoolsite.com/subfolder instead of being restricted to using https://mycoolsite.com

If this is something that'd be useful i'd like to take a stab at it. Would love to get involved with next.js contributing.

@benhjames @arunoda https://github.com/zeit/next.js/pull/2145 solves this. Technically the existing assetPrefix option works, but it then breaks next dev because my file structure doesn't match the one needed to make static site work on github.

Was this page helpful?
0 / 5 - 0 ratings