-
Notifications
You must be signed in to change notification settings - Fork 27.8k
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
Hosting on GitHub Pages #3335
Comments
I solved the issue with Firebase + Cloudfront : https://react-swipeable-views.com/. For smaller projects, I wish I could simply deploy to a GitHub Page. |
You can define an That way you can deploy to a GH page, the Wiki guide explain how to avoid issues with jekyll ignoring files prefixed with |
@sergiodxa You are right, However, it only solves the assets loading issue. You still gonna have issues with the navigation. |
Take a look to my config file. |
@thierryc Thanks for providing a reproduction example 👍 .
|
This may can help you. |
@oliviertassinari I fixe it. (hope) try :
|
@thierryc The following approach is interesting: const prod = process.env.NODE_ENV === 'production'
module.exports = {
'process.env.BACKEND_URL': prod ? 'https://anotherplanet-io.github.io/Next-React-Components' : ''
} Unfortunately, it comes with a new issue. Any page transition will reload the whole page. You lose the client page transitions. For instance, you can't preload the next page. |
Yes I know. Interesting approach but 👎 solution. |
By the way, @thierryc — not sure if you're aware, but your I'm actually now using the same approach as @thierryc for the env variable, because the Any other recommendations? @sergiodxa @oliviertassinari |
Thank you @jabacchetta, I add it! But the real problem is: The next router is /absolute 1st loading: the route is https://anotherplanet-io.github.io/Next-React-Components not If you reload the page, you get a 404 error. I add the prefix ('process.env.BACKEND_URL' ) to every link.
BUT Unfortunately, it comes with a new issue. Thank you to @oliviertassinari to point it ! I also try Do you have any suggestions. |
Eureka ! 🛁 @sergiodxa @oliviertassinari @jabacchetta 👍 use:
env-config.js
This solution works for me ! Do you confirm ? Refresh 👍 or 👎 |
I create an example for Next.js A Github gh-pages Example to replace Doctor Jekyll. Test it : /~https://github.com/thierryc/Next-gh-page-exemple/
https://thierryc.github.io/Next-gh-page-exemple/
/~https://github.com/thierryc/next.js
|
Looking good, @thierryc! I've got this exact setup on my page as well. The |
Yes git is handy (git subtree push) ! next build
&& next export
&& touch out/.nojekyll
&& git add out/
&& git commit -m \"Deploy Next.js to gh-pages\"
&& git subtree push --prefix out origin gh-pages"
|
@thierryc Looks like it's working :). |
Also, for anyone that is using a custom domain:
next build
&& next export
&& touch out/.nojekyll
&& touch out/CNAME
&& echo \"example.com\" >> out/CNAME
&& git add out/
&& git commit -m \"Deploy to gh-pages\"
&& git subtree push --prefix out origin gh-pages" |
While using babel-transform method,there is a resulting cache issue. |
I got most of my app to publish correctly in gh-pages (a project branch). My one problem is that the asset path I have for a background image is not getting properly prefixed in the build. I used styled-jsx to write the CSS - here is a snippet:
Works fine in regular served mode and regular static mode (without project prefix). I have another project that works fine when I set |
An easier approach is using push-dir to push a directory to a specific branch. First install via NPM next build
&& next export
&& touch out/.nojekyll
&& touch out/CNAME
&& echo \"example.com\" >> out/CNAME
&& push-dir --dir=out --branch=gh-pages (based on @jabacchetta's script) |
@thierryc I guess you could also wrap import Link from 'next/link';
import React from 'react';
import PropTypes from 'prop-types';
export default class PrefixedLink extends React.Component {
render () {
const { href, as = href, ...props } = this.props;
const { prefix = '' } = this.context;
return <Link href={href} as={`${prefix}${as}`} {...props} />;
}
}
PrefixedLink.contextTypes = {
prefix: PropTypes.string
};
export class PathPrefix extends React.Component {
getChildContext () {
return { prefix: this.props.prefix || '' };
}
render () {
return this.props.children;
}
}
PathPrefix.childContextTypes = {
prefix: PropTypes.string
}; Would be used as import Link, { PathPrefix } from './my-link'
export function MyApp () {
return (
<PathPrefix prefix={process.env.BACKEND_URL}>
<Link href='/about'>About</Link>
</PathPrefix>
)
} Maybe this could even be part of the router API? like import { withPathPrefix } from `next/router` |
This issue can be closed as deploying to github pages works fine, eg zeit-status.co. |
@hipstersmoothie thanks a lot for your article. I'll try. Could you post the similar but not identical procedure to publish to a personal page? |
That was the procedure on how to publish to a personal github.io page. So i'm not sure what you're asking. |
Hi guys, here is my solution for altering the links (if you deploy on not main repository), hope it will be helpful to somebody: Next allows to set environmental variables in next.config.js now. This way all the configurations are stored in the same place. next.config.js
Here I create a custom HOC, which basically adds the linkPrefix from before to all the links 'as'. components/Link.js
here is my package.json scripts, you will need to install gh-pages though.
|
@melanievillela, I don't know where is this article but, how may I can help you? This is my first example /~https://github.com/thierryc/Next-gh-page-example. |
@thierryc, I am using 6.4.1 |
@melanievillela I will update my example. I keep you posted. |
/~https://github.com/thierryc/Next-gh-page-example is up to date now. I use gh-pages package to publish it. (More simple). |
@thierryc, why does https://thierryc.github.io/ show 404? I am trying to deploy to https://melanievillela.github.io/ and I used build and export but still is not working. |
@melanievillela the example is a hp-page project, not a user gh-page. The path is not the same. I will do my personal gh-page today (or tomorrow). I keep you posed (I will share it to you) |
@melanievillela My personal gh-page example /~https://github.com/thierryc/thierryc.github.io 2 interesting point.
I use deploy to push the source into the master. If you get an issue to push it (deploy) just delete the master and deploy again.
|
@thierryc - I will look at it very interesting about the default branch! |
@melanievillela The only way to keep your repo clean... |
There are a lot of mentions to |
See full working instructions here: #9753 (comment) (hopefully it'll get folded onto the wiki page). |
@rafaeleyng "assetPrefix" nice catch. |
Adding a .nojekyll file in the same directory that contains the _next folder fixed the issue for me. There are more details in this Stack Overflow question. |
@kas's solution fixed it for me, even when using a custom domain. See: pojntfx/nebulark@911ca45 |
prøver å fikse at static-assets ikke funker på gh-pages vercel/next.js#3335 https://stackoverflow.com/questions/61450307/js-and-css-not-loading-when-hosting-next-application-on-github-pages/64493580#64493580
Getting Next.js routes to play nice with GitHub Pages, trying this solution: vercel/next.js#3335 (comment)
@kas's solution worked for me as well, except I also had to add the following to my
Which I got from here. This is because, from what I saw in my Chrome devtools, without the My site is deployed from a gh-pages branch (not default branch) with no custom domain name. |
actually, when i use custom domain setting. the files in the |
Damn, I did not realise that this was so frustratingly complex, so there appears to be a mix of adding EDIT: So I had to do a few things, to get this to nicely work, the back end is an absolute mess. The site is hosted on the Currently spent way too long on this damned process to get this to work, but basically I had a Then I had this in my
I have a bash script that just does a:
Where I do the build inside the directory (on the branch that I want to deploy the ghpages) and the copy out the output to the root of the directory, commit the build and then push the changes out to github. Then switch the branch of ghpages to the branch...I hate at how I have to do this must stuff just to host the darn HTML page. |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Expected Behavior
I can host a Next.js app on a GitHub Pages.
Current Behavior
As far as I have digged into the issue, we can't host a Next.js app on a GitHub Pages because of the location of the hosting:
http://username.github.io/project-name/
. It would be working perfectly if we hadhttp://project-name.github.io/
.Steps to Reproduce (for bugs)
Humm. I'm not sure it's relevant. I can provide something if it help. I noticed the issue with http://oliviertassinari.github.io/react-swipeable-views/.
Context
Deploying a Next.js app into GitHub Pages guide is misleading. It's not possible as far as I know.
Your Environment
The text was updated successfully, but these errors were encountered: