rafgraph / spa-github-pages

Host single page apps with GitHub Pages
https://spa-github-pages.rafgraph.dev
MIT License
3.83k stars 565 forks source link

Github pages served from master branch /docs without custom domain #25

Closed mcauser closed 3 years ago

mcauser commented 6 years ago

Changes to run this as a Project Page served from the /docs folder on the master branch: eg. http://username.github.io/spa

/docs/404.html

var segmentCount = 1;

/docs/index.html

<script src="/spa/build/bundle.js"></script>

/src/index.js

<BrowserRouter basename="/spa">

/package.json

"start": "webpack-dev-server --devtool eval-source-map --content-base docs/ --history-api-fallback --open --openPage spa/",

/webpack.config.js

output: {
  path: `${__dirname}/docs/build`,
  publicPath: '/spa/build/',
  filename: 'bundle.js',
},

Install React and dependencies. Build and start the webpack dev server.

npm install
npm run build
npm start

Opens: http://localhost:8080/spa/

Instantiate the repository and push to GitHub

git init
git add .
git init
git commit -m "first commit"
git remote add origin git@github.com:username/spa.git
git push -u origin master
ackernaut commented 6 years ago

👏 this helps a lot!

cadenzah commented 4 years ago

Setting basename props in <BrowserRouter /> is the key point of this.

rafgraph commented 3 years ago

Thanks for this. I added a section to the readme on how to use the /docs folder for the build and the root / for the source code.