<!DOCTYPE html>
Create static Websites with Vite React & Markdown, Host for Free on GitHub Pages
Building static websites has become a popular choice for many developers, as they are fast, secure, and easy to host. In this tutorial, we will be using Vite, React, and Markdown to create a static website, which we will then host for free on GitHub Pages.
Step 1: Setting up Vite with React
Vite is a build tool that is designed to make the development process faster and more efficient. To set up Vite with React, we first need to install Vite using npm:
npm install -g create-vite
Now, we can create a new Vite project with React by running the following command:
create-vite my-static-website --template react
This will create a new Vite project with React, which we can then start by running:
cd my-static-website npm run dev
Step 2: Using Markdown with React
Markdown is a lightweight markup language that is commonly used for creating content for websites. We can use Markdown with React by installing the markdown-to-jsx package:
npm install markdown-to-jsx
Now, we can import Markdown files into our React components and render them using markdown-to-jsx. Here is an example of how we can render a Markdown file:
“`jsx
import ReactMarkdown from ‘react-markdown’;
const MyComponent = () => {
return (
{`
# My Markdown Content
This is my markdown content.
`}
);
};
export default MyComponent;
“`
Step 3: Hosting on GitHub Pages
GitHub Pages is a free service provided by GitHub that allows you to host static websites directly from a GitHub repository. To host our static website on GitHub Pages, we need to first create a new repository on GitHub and push our project to it:
git init git add . git commit -m "Initial commit" git remote add origin https://github.com/your-username/my-static-website.git git push -u origin master
Next, we need to enable GitHub Pages for our repository by going to the repository settings and selecting the branch and directory for our website. Once enabled, our static website will be accessible at https://your-username.github.io/my-static-website.
And there you have it! With Vite, React, and Markdown, you can easily create static websites and host them for free on GitHub Pages. Happy coding!