Deploying React App to Github Pages (gh-pages) #2419
-
I have looked at posts regarding deployment to gh-pages but these do not work. I get a blank page (which has the title defined in my index.html - so I know it is there) file and can see 404 errors in the console where page is unable to open react.js and react-dom.js. If I unpack the gh-pages branch in my repository to a local test machine it works fine. I have no problems achieving the same with react app created using create-react-app.
Is someone able to provide guidelines to publishing a react app using Snowpack to gh-pages? My process has been
deploy using PS: I have also tries adding Help appreciated |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 2 replies
-
OK I managed to get this partially working. Gh-Pages serves its pages relative to the root of the git hub user name. This meants that /build refers to the build directory in the users main github page and not the repositiry. Adding |
Beta Was this translation helpful? Give feedback.
-
Hi @Intelliflex thanks for reporting. I don't know why this is happening. I can ask around our community to see if anyone has any experience working with gh-pages. |
Beta Was this translation helpful? Give feedback.
-
TL;DR for people looking for a solution
TL;DR for Snowpack maintaners
Longer versionHad a similar problem with my repo. My issue was that that the script tag in Luckily, there's a snowpack build option for this:
Unfortunately, this didn't work for me (I guess that's a bug), so I ended up manually setting the absolute path in Second issue was that the
That worked. I suggest renaming the Almost all my files seem to resolve, yay! But there's a new problem... There's one file with an underscore: So... I decided to bundle my app into a single .js file. And that worked! |
Beta Was this translation helpful? Give feedback.
-
Just saw this blog post and thought it might also prove helpful: https://blog.kaiser.lol/snowpack-github-actions/ |
Beta Was this translation helpful? Give feedback.
-
Hello, export default "/dist/logo.svg"; We should be able in our code to do import React from 'react';
import logo from './logo.svg';
const App = () => (
<img src={logo} className="App-logo" alt="logo" />
); and not have to do when using import React from 'react';
const App = () => (
<img src="dist/logo.svg" className="App-logo" alt="logo" />
); |
Beta Was this translation helpful? Give feedback.
-
Just wanted to pop in here for others coming across this in the future, I had some extraneous values in my My whole /** @type {import("snowpack").SnowpackUserConfig } */
module.exports = {
mount: {
public: { url: '/', static: true },
src: { url: '/dist' },
},
plugins: ['@snowpack/plugin-react-refresh', '@snowpack/plugin-typescript'],
workspaceRoot: '../../',
routes: [],
optimize: {
bundle: true,
},
devOptions: {
open: 'none',
},
buildOptions: {
metaUrlPath: 'snowpack',
baseUrl: './',
},
}; (The And works well in Github Pages finally 👍 |
Beta Was this translation helpful? Give feedback.
TL;DR for people looking for a solution
buildOptions.metaUrlPath
to something without an underscore (e.g.dist
)optimize.bundle
totrue
to create a single .js file, hopefully without underscoresindex.html
file to set some absolute URLs:<script type="module" src="https://joepio.github.io/atomic-react/dist/index.js"></script>
TL;DR for Snowpack maintaners
_underscores
(which break the_snowpack
folder and some other files).baseUrl
setting does not work (as far as I can tell)Longer version
Had a similar problem with my repo. My issue was that that the script tag in
index.html
lin…