Skip to content

Commit 0824800

Browse files
committed
add final changes
1 parent c7e4232 commit 0824800

File tree

5 files changed

+171
-12
lines changed

5 files changed

+171
-12
lines changed

README.md

+163-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,166 @@
1-
# React + Vite
1+
![image](./public/snap.png)
22

3-
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
3+
![Static Badge](https://img.shields.io/badge/react-v18%2e3%2e1-58c4dc) ![Static Badge](https://img.shields.io/badge/tailwindcss-v3%2e4%2e7-38bdf8)
44

5-
Currently, two official plugins are available:
5+
"[React](https://react.dev/) lets you build user interfaces out of individual pieces called components. Create your own React components like `Thumbnail`, `LikeButton`, and `Video`. Then combine them into entire screens, pages, and apps."
66

7-
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
7+
This guide provides a first-hand experience on building a **React** project using [Vite](https://vitejs.dev/guide/#scaffolding-your-first-vite-project) + [Tailwind CSS](https://tailwindcss.com/) and deploying it on [GitHub Pages](https://pages.github.com/).
8+
9+
## 🛠️ Installation
10+
11+
**1. Create your project.**
12+
13+
```bash
14+
# terminal
15+
npm create vite@latest project_name -- --template react
16+
cd project_name
17+
```
18+
19+
**2. Install Tailwind CSS.**
20+
21+
```bash
22+
# terminal
23+
npm install -D tailwindcss postcss autoprefixer
24+
npx tailwindcss init -p
25+
```
26+
27+
**3. Configure your template paths.**
28+
29+
```js
30+
// tailwind.config.js
31+
/** @type {import('tailwindcss').Config} */
32+
module.exports = {
33+
content: ['./src/**/*.{js,jsx,ts,tsx}'],
34+
theme: {
35+
extend: {},
36+
},
37+
plugins: [],
38+
};
39+
```
40+
41+
**4. Add the Tailwind directives to your CSS.**
42+
43+
```css
44+
/* index.css */
45+
@tailwind base;
46+
@tailwind components;
47+
@tailwind utilities;
48+
```
49+
50+
**5. Start coding.**
51+
52+
```jsx
53+
<p className="text-red-400 font-bold mt-10">Tailwind is working.</p>
54+
```
55+
56+
## 🗂️ File Structure
57+
58+
Simple file structure example by grouping `file types`.
59+
60+
```
61+
src/
62+
├── assets/
63+
├── api/
64+
├── configs/
65+
├── components/
66+
│ ├── SignUpForm.tsx
67+
│ ├── Employees.tsx
68+
│ ├── PaymentForm.tsx
69+
│ └── Button.tsx
70+
├── hooks/
71+
│ ├── usePayment.ts
72+
│ ├── useUpdateEmployee.ts
73+
│ ├── useEmployees.ts
74+
│ └── useAuth.tsx
75+
├── lib/
76+
├── services/
77+
├── states/
78+
└── utils/
79+
```
80+
81+
## 🛫 How to deploy to GitHub Pages
82+
83+
Deploying to github pages is totally up to you, be it through **[GitHub Actions](https://docs.github.com/en/actions/deployment/about-deployments/deploying-with-github-actions)**, or via **[gh-pages](https://www.npmjs.com/package/gh-pages)**, or manually.
84+
85+
> [!NOTE]
86+
>
87+
> Also take note that [GitHub Pages](https://pages.github.com/) have limitations, it's free, yes, but it has a limit.
88+
89+
### ❗ via package ❗
90+
91+
**1. Install `gh-pages` package.**
92+
93+
```bash
94+
npm install gh-pages --save-dev
95+
```
96+
97+
**2. Modify file paths.**
98+
99+
```html
100+
<!-- index.html -->
101+
102+
<link rel="icon" type="image/svg+xml" href="./vite.svg" />
103+
<script type="module" src="./src/main.jsx"></script>
104+
```
105+
106+
**3. Add base path to your repo in `vite.config.js`.**
107+
108+
```js
109+
// vite.config.js
110+
import { defineConfig } from 'vite';
111+
import react from '@vitejs/plugin-react';
112+
113+
// https://vitejs.dev/config/
114+
export default defineConfig({
115+
base: '/react/',
116+
plugins: [react()],
117+
});
118+
```
119+
120+
**4. Add `deploy` to your scripts.**
121+
122+
```json
123+
{
124+
"scripts": {
125+
"deploy": "npm run build && gh-pages -d dist -t true"
126+
}
127+
}
128+
```
129+
130+
**5. Create and configure a new branch for `gh-pages`.**
131+
132+
> [!IMPORTANT]
133+
>
134+
> Make sure that you have committed your changes before doing this. All untracked and staged files may be deleted.
135+
>
136+
> I like to do this manually. If there is some automated way, feel free to let me know by any means.
137+
138+
```bash
139+
git checkout --orphan gh-pages
140+
git reset --hard
141+
git commit --allow-empty -m 'commit_message'
142+
git push origin gh-pages
143+
```
144+
145+
**6. Publish the production build.**
146+
147+
```bash
148+
npm run deploy
149+
```
150+
151+
### ❗ via manually configuring github pages settings ❗
152+
153+
**1. Create your project.**
154+
Start coding your project, either use a framework like React, Vue, or not.
155+
156+
**2. Publish production build to GitHub.**
157+
Push your _production build_ to your github repo. After that, check if your `index.html` file is uploaded, since it is one of the core files needed for your website to work.
158+
159+
**3. Configure your GitHub Pages on repo Settings.**
160+
Navigate to `Settings > Pages > Build and deployment`. Make sure the **Source** says 'Deploy from a branch', and then configure the **Branch** settings and change it to your branch with the files.
161+
162+
---
163+
164+
🌎 [kerbethecoder](https://kerbethecoder.com/)
165+
166+
📌 July 30, 2024

index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
<!doctype html>
1+
<!DOCTYPE html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
5-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
5+
<link rel="icon" type="image/svg+xml" href="./vite.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>Vite + React</title>
88
</head>
99
<body>
1010
<div id="root"></div>
11-
<script type="module" src="/src/main.jsx"></script>
11+
<script type="module" src="./src/main.jsx"></script>
1212
</body>
1313
</html>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build": "vite build",
99
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
1010
"preview": "vite preview",
11-
"deploy": "npm run build && gh-pages -d public"
11+
"deploy": "npm run build && gh-pages -d dist -t true"
1212
},
1313
"dependencies": {
1414
"react": "^18.3.1",

public/snap.png

48.5 KB
Loading

vite.config.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { defineConfig } from 'vite'
2-
import react from '@vitejs/plugin-react'
1+
import { defineConfig } from 'vite';
2+
import react from '@vitejs/plugin-react';
33

44
// https://vitejs.dev/config/
55
export default defineConfig({
6+
base: '/react/',
67
plugins: [react()],
7-
})
8+
});

0 commit comments

Comments
 (0)