Vite JS Tutorial: Deploying to GitHub Pages

beginner
13 min

Vite JS Tutorial: Deploying to GitHub Pages

Welcome to our comprehensive guide on deploying your Vite.js project to GitHub Pages! This tutorial is designed for both beginners and intermediates, so let's get started.

šŸŽÆ Understanding GitHub Pages

GitHub Pages is a service that allows you to host a static website directly from a GitHub repository. It's perfect for showcasing your projects, creating personal blogs, or even hosting documentation.

šŸ“ Note:

  • You'll need a GitHub account to follow along. If you don't have one, create one here.

šŸ’” Setting up your Vite.js project

First, let's ensure you have Vite.js installed. Follow the official Vite.js guide to set up a new project.

šŸŽÆ Creating a GitHub Repository

  1. Log into your GitHub account.
  2. Click on the + icon in the upper right corner and select New repository.
  3. Name your repository (e.g., my-vite-project), make it public, and initialize with a README.

šŸ’” Connecting your Vite.js project to GitHub

  1. Navigate to your project's directory in your terminal.
  2. Initialize a Git repository by running git init.
  3. Add all your files to Git using git add ..
  4. Commit your changes with a message like Initial commit. Run git commit -m "Initial commit".

šŸŽÆ Pushing your project to GitHub

  1. Link your local repository to the GitHub repository you created earlier. Use git remote add origin https://github.com/yourusername/my-vite-project.git.
  2. Push your local repository to GitHub by running git push -u origin master.

šŸ’” Building your Vite.js project for GitHub Pages

By default, Vite.js bundles your project for development. To build it for production, run vite build. This will create a dist folder with your static files.

šŸŽÆ Configuring GitHub Pages

  1. Go to your GitHub repository settings.
  2. Scroll down to the GitHub Pages section.
  3. Under Source, select master branch.
  4. Your site URL should now be displayed. Refresh the page to see it.

šŸ’” Quiz Time!

Quick Quiz
Question 1 of 1

What should you select under `Source` in GitHub Pages settings?

And there you have it! You've successfully deployed your Vite.js project to GitHub Pages. Keep learning, and happy coding! šŸŽ‰

Remember, practice makes perfect. Try deploying different projects and experimenting with various Vite.js features to deepen your understanding.

Want to learn more about Vite.js? Check out our other Vite.js tutorials here on CodeYourCraft.

šŸ’” Pro Tip: To learn more about Git and GitHub, visit CodeYourCraft's Git & GitHub Tutorial. šŸŽÆ