This project is a modern, animated website showcasing the Zentry Metaverse platform, built with React and Vite. It features various sections including a hero area with video transitions, about, features (using a bento grid layout), story, and contact sections, along with GSAP animations and React Router for navigation.
/public # Static assets (images, videos, fonts, audio)
/src
/components # Reusable React components for different sections
App.jsx # Main application component with routing
main.jsx # Entry point of the React application
index.css # Global styles and Tailwind base/utilities
vite.config.js # Vite configuration file
package.json # Project dependencies and scripts
README.md # This file
... # Other configuration files (ESLint, PostCSS, etc.)
- React: JavaScript library for building user interfaces.
- Vite: Fast frontend build tool.
- Tailwind CSS: Utility-first CSS framework.
- GSAP (GreenSock Animation Platform): JavaScript library for high-performance animations.
- React Router: Declarative routing for React applications.
- gh-pages: Utility for deploying files to a
gh-pages
branch on GitHub.
- Clone the repository:
git clone https://github.com/WWI2196/zentry-metaverse.git cd zentry-metaverse
- Install dependencies:
npm install
- Run the development server:
This will start the Vite development server, typically at
npm run dev
http://localhost:5173
.
npm run build
This command builds the application for production in the dist
directory.
This project uses GitHub Actions for automated deployment. Here's a breakdown of the setup, including the troubleshooting steps we identified:
A. Configuration Steps (Do these once):
- Install
gh-pages
(Optional but good practice): While GitHub Actions handles the deployment, havinggh-pages
locally can be useful for testing or manual deployments.npm install gh-pages --save-dev
- Update
package.json
:- Add a
homepage
field pointing to your GitHub Pages URL:(In this project, it's"homepage": "https://<your-username>.github.io/<your-repo-name>/"
https://wwi2196.github.io/zentry-metaverse/
) - (Optional) Add
predeploy
anddeploy
scripts for manual deployment:"scripts": { // ... other scripts "predeploy": "npm run build", "deploy": "gh-pages -d dist" }
- Add a
- Configure Vite Base Path:
- In
vite.config.js
, set thebase
option to your repository name (including leading and trailing slashes). This is crucial for assets to load correctly on GitHub Pages.// vite.config.js import { defineConfig } from 'vite'; // ... other imports export default defineConfig({ // ... plugins base: '/<your-repo-name>/', // e.g., '/zentry-metaverse/' });
- In
- Configure React Router Basename:
- If using React Router, wrap your routes in a
<Router>
component and provide thebasename
prop matching the Vitebase
path (without the trailing slash). This ensures routing works correctly within the subdirectory on GitHub Pages.// src/App.jsx import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; function App() { return ( <Router basename="/<your-repo-name>"> {/* e.g., "/zentry-metaverse" */} {/* ... Routes ... */} </Router> ); }
- If using React Router, wrap your routes in a
- Import Static Assets:
- Crucially, for Vite to correctly handle asset paths during the build, especially when deploying to a subdirectory, you must
import
static assets (images, videos, audio files) into your JavaScript/JSX files and use the imported variable as thesrc
or instyle
attributes. - Example:
// Instead of: <img src="/img/logo.png" alt="Logo" /> // Do this: import logoSrc from '/img/logo.png'; // ... later in the component <img src={logoSrc} alt="Logo" /> // Similarly for background images in style props: import bgImage from '/img/background.webp'; // ... <div style={{ backgroundImage: `url(${bgImage})` }}>...</div>
- This ensures Vite processes the assets and generates the correct URLs relative to the
base
path in the final build. Using absolute paths like/img/logo.png
directly insrc
attributes will likely result in 404 errors on the deployed GitHub Pages site.
- Crucially, for Vite to correctly handle asset paths during the build, especially when deploying to a subdirectory, you must
B. GitHub Actions Workflow Setup:
- Create Workflow File:
- Create a directory structure
.github/workflows
in the root of your project if it doesn't exist. - Inside
.github/workflows
, create a file nameddeploy.yml
(or any other.yml
name).
- Create a directory structure
- Add Workflow Content:
- Paste the following content into
deploy.yml
. This is a standard workflow for deploying Vite projects to GitHub Pages:# Simple workflow for deploying static content to GitHub Pages name: Deploy static content to Pages on: # Runs on pushes targeting the default branch push: branches: ["main"] # Or your default branch name # Allows you to run this workflow manually from the Actions tab workflow_dispatch: # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages permissions: contents: read pages: write id-token: write # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. concurrency: group: "pages" cancel-in-progress: false jobs: # Build job build: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Set up Node uses: actions/setup-node@v4 with: node-version: 20 # Use a recent LTS version cache: 'npm' - name: Install dependencies run: npm install - name: Build run: npm run build - name: Setup Pages uses: actions/configure-pages@v5 - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: # Upload dist folder path: './dist' # Deployment job deploy: environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest needs: build steps: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4
- Paste the following content into
- Commit and Push:
- Commit the
.github/workflows/deploy.yml
file and push it to your default branch (main
).
- Commit the
C. GitHub Repository Settings:
- Navigate to Settings: Go to your repository on GitHub.
- Go to Pages: Click on the "Settings" tab, then select "Pages" from the left sidebar.
- Configure Source: Under "Build and deployment", select "GitHub Actions" as the source.
D. Deployment Process:
- Now, every time you push changes to your
main
branch (or whichever branch you specified indeploy.yml
), the GitHub Action will automatically:- Check out your code.
- Set up Node.js.
- Install dependencies (
npm install
). - Build the project (
npm run build
). - Upload the build output (
dist
folder) as a GitHub Pages artifact. - Deploy the artifact to your GitHub Pages site.
- You can monitor the progress in the "Actions" tab of your repository.
- Your site will be available at the URL specified in your
homepage
field inpackage.json
(e.g.,https://wwi2196.github.io/zentry-metaverse/
).
(Previous steps 6 & 7 about manual deployment and gh-pages branch settings are removed as they are superseded by the GitHub Actions setup)
This project was heavily inspired by and references resources from Adrian Hajdin. Special thanks for his valuable content:
- GitHub: github.com/adrianhajdin