A modern React application built with TypeScript and Vite, featuring CI/CD pipeline with GitHub Actions and automatic deployment to GitHub Pages.
- React 18 with TypeScript support
- Vite build tool for fast development and optimized production builds
- GitHub Actions CI/CD pipeline
- Automated deployment to GitHub Pages
- ESLint configuration for code quality
- Source maps for better debugging experience
-
Clone the repository:
git clone https://github.com/reaper1067MSX/react-functional-components.git cd react-functional-components -
Make sure you have Node.js 18.0.0 or higher installed:
node --version
-
Install dependencies:
npm install
This project uses npm as the package manager. The lock file (package-lock.json) ensures consistent installations across environments.
- Do not delete the lock file
- If using another package manager (yarn, pnpm), convert the lock file appropriately
- Commit lock file changes to version control
-
Development server:
npm run dev
Runs the TypeScript compiler and starts the Vite development server with HMR.
-
Linting:
npm run lint
Runs ESLint to check for code quality issues.
-
Production build:
npm run build
Compiles TypeScript and builds the project for production.
-
Preview production build:
npm run preview
Previews the production build locally.
This project uses ESLint for code quality and consistent style. The current configuration supports both JavaScript and TypeScript with React-specific rules.
The ESLint configuration includes:
// eslint.config.js
import { defineConfig } from 'eslint-define-config';
import tseslint from 'typescript-eslint';
export default defineConfig({
extends: [
...tseslint.configs.recommendedTypeChecked,
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
],
plugins: ['react-refresh'],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
parserOptions: {
project: ['./tsconfig.json'],
tsconfigRootDir: import.meta.dirname,
},
},
settings: {
react: {
version: 'detect'
}
},
rules: {
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
'react/react-in-jsx-scope': 'off',
'react/prop-types': 'off',
}
});For enhanced linting, consider adding these plugins:
npm install --save-dev eslint-plugin-react-hooks eslint-plugin-jsx-a11y eslint-plugin-react-refreshYou can also enhance the configuration with accessibility rules:
// Add to the extends array
'plugin:jsx-a11y/recommended',The project is configured for automatic deployment to GitHub Pages. The configuration in vite.config.ts includes:
// Base URL configuration for GitHub Pages deployment
base: '/react-functional-components/',
// Build configuration
build: {
// Generate source maps for better debugging experience
sourcemap: true,
// Output directory (default is 'dist')
outDir: 'dist',
// Clean the output directory before build
emptyOutDir: true,
}After deployment, the application is available at: https://reaper1067msx.github.io/react-functional-components/
The project uses GitHub Actions for continuous integration and deployment.
The CI/CD pipeline is defined in .github/workflows/deploy.yml and is triggered on:
- Push to the
mainbranch - Pull requests to the
mainbranch - Manual trigger via the GitHub Actions interface or GitHub CLI
The workflow consists of two main jobs:
1. Build and Test:
- Checks out the code
- Sets up Node.js environment
- Installs dependencies
- Lints the code
- Builds the project
- Uploads build artifacts
2. Deploy to GitHub Pages:
- Only runs on push events to the
mainbranch - Downloads the build artifacts
- Deploys to GitHub Pages using JamesIves/github-pages-deploy-action
To view the status of workflow runs, go to the "Actions" tab in the GitHub repository.
This section provides detailed instructions on how to set up and customize the CI/CD pipeline and GitHub Pages deployment.
To enable GitHub Pages for your repository:
- Go to your repository on GitHub
- Navigate to Settings > Pages (under Code and automation)
- In the Build and deployment section:
- Set Source to "GitHub Actions"
- Save the changes
If you have GitHub CLI installed, you can use these commands to manage and monitor your workflows:
# List recent workflow runs
gh run list -L 5
# View details of a specific workflow run
gh run view <run-id>
# Watch a workflow run in real-time
gh run watch <run-id>
# View logs of a failed workflow
gh run view <run-id> --log-failed
# Rerun a failed workflow
gh run rerun <run-id>
# Manually trigger the deployment workflow
gh workflow run "Build and Deploy" --ref mainYou can manually trigger the deployment process in several ways:
-
Using GitHub CLI:
gh workflow run "Build and Deploy" --ref main -
Using GitHub Web Interface:
- Go to your repository on GitHub
- Navigate to the Actions tab
- Select the Build and Deploy workflow from the left sidebar
- Click the Run workflow button
- Select the main branch and click Run workflow
Manual deployments are useful when:
- You need to redeploy without code changes
- You're troubleshooting deployment issues
- The automatic deployment failed for some reason
The workflow is defined in .github/workflows/deploy.yml. Here are some common customizations:
-
Changing the Node.js version:
- name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20' # Change to your preferred version
-
Modifying build commands:
- name: Build project run: npm run build # Change to your build command
-
Changing the deployment branch:
- name: Deploy to GitHub Pages uses: JamesIves/github-pages-deploy-action@v4 with: folder: dist branch: gh-pages # Change to your preferred branch
-
Deployment Failure:
- Check if GitHub Pages is enabled in repository settings
- Ensure the workflow has proper permissions (contents: write)
- Verify that the build is generating files in the correct folder
-
Build Failure:
- Check for syntax errors in your code
- Ensure all dependencies are properly installed
- Verify that your build scripts are correct
-
Base URL Issues:
- If your site has 404 errors or missing assets, check that the base URL in
vite.config.tsmatches your repository name
- If your site has 404 errors or missing assets, check that the base URL in
-
Blank Page After Deployment:
- Check the browser console for errors (F12 in most browsers)
- Verify that the
gh-pagesbranch contains the expected files withgit checkout gh-pages - Clear your browser cache or try in incognito/private mode
- Check that the assets paths in the HTML file include the correct base URL
- Try a manual deployment to refresh all files
To check if your site has been deployed:
- Go to the Actions tab in your repository
- Click on the latest workflow run
- If successful, you should see all checkmarks
- Your site will be available at:
https://<username>.github.io/<repository-name>/
You can also see deployment history and details in the Environments section of your repository.
If you're experiencing issues with your deployed site, you can force a clean deployment:
-
Delete and recreate the gh-pages branch:
# Delete the gh-pages branch locally and remotely git branch -D gh-pages # Local deletion (if exists) git push origin --delete gh-pages # Remote deletion # Then trigger a manual deployment gh workflow run "Build and Deploy" --ref main
-
Use the single-commit option: The workflow is configured with
single-commit: truewhich ensures the deployment branch contains only a single commit with the latest files, reducing potential conflicts.