Skip to content

Commit 0d541a9

Browse files
committed
Add deploy docs for SPA and GitHub Pages.
1 parent 1987db1 commit 0d541a9

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

docs/Deploy.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
layout: default
3+
title: "Deploy React-admin"
4+
---
5+
6+
# Deploy React-admin
7+
8+
You have created an awesome React-admin application. Well done! But now, you want to deploy your application in production so users can actually use it.
9+
10+
## Single Page Application
11+
12+
React-admin is a framework to build [Single Page Applications](https://developer.mozilla.org/en-US/docs/Glossary/SPA). It means that your app can be served by a simple static web server.
13+
14+
**Warning**: If you chose Next.js or Remix, you **have to use a dynamic web server** (e.g. CloudFlare pages, Vercel, etc.).
15+
16+
With the default configuration of React-admin, that you can have using [`create-react-admin`](./CreateReactAdmin.md), you are already configured to run `yarn build` or `npm run build` to compile your application with [`vite`](https://vite.dev).
17+
18+
This builds your application in the `dist` directory in application root. Let's have a look to what's in there:
19+
20+
```tree
21+
dist/
22+
├ assets/
23+
│ └ index-F74jyUxd.js
24+
├ favicon.ico
25+
├ index.html
26+
└ manifest.json
27+
```
28+
29+
As you can see, your app is contained in a single Javascript file, used in a simple `index.html`. To deploy your application, you just need to serve this directory with all URLs handled by `index.html`.
30+
31+
There are multiple easy ways to deploy your app automatically to various hosts which does not require you to setup a web server manually. Some of these are addressed in this page.
32+
33+
## Deploy With GitHub Actions And GitHub Pages
34+
35+
You can deploy your application with [GitHub Pages](https://pages.github.com) by setting up a [GitHub Actions](https://github.com/features/actions) workflow. To set it up, you need to [configure the source of your GitHub Pages to GitHub Actions](https://docs.github.com/en/pages/getting-started-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site#publishing-with-a-custom-github-actions-workflow).
36+
37+
Then, initialize a new workflow in `.github/workflows/admin.yml` with the following content:
38+
39+
```yaml
40+
name: Build and deploy React-admin
41+
42+
on:
43+
push:
44+
branches:
45+
- main
46+
47+
jobs:
48+
build:
49+
name: Build the admin panel to be deployed
50+
runs-on: ubuntu-latest
51+
environment: github-pages
52+
steps:
53+
# Pull the latest version of the application.
54+
- uses: actions/checkout@v4
55+
56+
# Setup NodeJS tools.
57+
- uses: actions/setup-node@v4
58+
with:
59+
node-version: lts/*
60+
- name: Enable corepack to use latest stable yarn
61+
run: corepack enable
62+
63+
# Build the React-admin application.
64+
- name: Build
65+
run: yarn build
66+
67+
# Upload the built application as a GitHub Pages artifact.
68+
- name: Upload static files as artifact
69+
uses: actions/upload-pages-artifact@v3
70+
with:
71+
path: dist/
72+
73+
deploy:
74+
name: Deploy React-admin application to GitHub Pages
75+
runs-on: ubuntu-latest
76+
needs: build
77+
78+
environment:
79+
name: github-pages
80+
url: ${{ steps.deployment.outputs.page_url }}
81+
82+
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
83+
permissions:
84+
pages: write # to deploy to Pages
85+
id-token: write # to verify the deployment originates from an appropriate source
86+
87+
steps:
88+
# Deploy the GitHub Pages artifact.
89+
- name: Deploy artifact to GitHub Pages
90+
uses: actions/deploy-pages@v4
91+
```
92+
93+
This workflow will run everytime you push or merge something in the main branch of your repository. You can find the URL of the deployed website in `Settings > Pages` in your GitHub repository.

docs/navigation.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<li {% if page.path == 'Vite.md' %} class="active" {% endif %}><a class="nav-link" href="./Vite.html">Vite</a></li>
1515
<li {% if page.path == 'NextJs.md' %} class="active" {% endif %}><a class="nav-link" href="./NextJs.html">Next.js</a></li>
1616
<li {% if page.path == 'Remix.md' %} class="active" {% endif %}><a class="nav-link" href="./Remix.html">Remix</a></li>
17+
<li {% if page.path == 'Deploy.md' %} class="active beginner" {% endif %}><a class="nav-link" href="./Deploy.html">Deploy</a></li>
1718
</ul>
1819

1920
<ul><div>Guides & Concepts</div>

0 commit comments

Comments
 (0)