<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vishal singh</title>
    <description>The latest articles on DEV Community by Vishal singh (@vsmentor).</description>
    <link>https://dev.to/vsmentor</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1021534%2F4b3321de-ab7c-4958-95d4-01bb9b30765c.jpg</url>
      <title>DEV Community: Vishal singh</title>
      <link>https://dev.to/vsmentor</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vsmentor"/>
    <language>en</language>
    <item>
      <title>Build A React Component with Vite</title>
      <dc:creator>Vishal singh</dc:creator>
      <pubDate>Mon, 19 Feb 2024 07:30:33 +0000</pubDate>
      <link>https://dev.to/vsmentor/build-a-react-component-with-vite-1ifm</link>
      <guid>https://dev.to/vsmentor/build-a-react-component-with-vite-1ifm</guid>
      <description>&lt;h2&gt;
  
  
  React
&lt;/h2&gt;

&lt;p&gt;React is a free and open-source front-end JavaScript library for building user interfaces based on components. It is maintained by Meta and a community of individual developers and companies. React can be used to develop single-page, mobile, or server-rendered applications with frameworks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Vite
&lt;/h2&gt;

&lt;p&gt;Vite is a next-generation, front-end tool that focuses on speed and performance. It consists of two major parts: A development server that provides rich feature enhancements over native ES modules: fast Hot Module Replacement (HMR), pre-bundling, support for typescript, jsx, and dynamic import.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Vite
&lt;/h2&gt;

&lt;p&gt;Vite is a rapid development tool for modern web projects.&lt;br&gt;
It focuses on speed and performance by improving the development experience.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgv14ely2lyux0qftvqpz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgv14ely2lyux0qftvqpz.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Compatibility Note:&lt;br&gt;
Vite requires Node.js version 18+. 20+. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step-by-Step Guide(React + Vite)
&lt;/h2&gt;

&lt;p&gt;React with Vite is a powerful combination for building fast and efficient web applications. Vite is a build tool that focuses on speed and development experience, utilizing ES modules for faster builds. Here's a basic guide on how to set up a React project with Vite:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new React project:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can also directly specify the project name and the template you want to use via additional command line options. For example, to scaffold a Vite + React project, run:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm create vite@latest


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next Step:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw2ado4c443nd9xwlpszs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw2ado4c443nd9xwlpszs.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next Step:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkjmsg91euiwfbyoqhzmh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkjmsg91euiwfbyoqhzmh.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2kesrmtdexhh53xomr71.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2kesrmtdexhh53xomr71.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install Vite:
Once you have a React project set up, navigate into the project directory and install Vite:&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm install


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Configure Vite for React:
Vite has built-in support for React, so you don't need any additional configuration for basic usage. However, you can use a 'vite.config.js' file in the project root for custom configurations if needed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;vite.config.js:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
})


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Modify package.json scripts:
Update the 'scripts' section in your 'package.json' file to use Vite for development:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;package.json:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

{
  "name": "react-vite",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
    "preview": "vite preview"
  },
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "devDependencies": {
    "@types/react": "^18.2.55",
    "@types/react-dom": "^18.2.19",
    "@vitejs/plugin-react": "^4.2.1",
    "eslint": "^8.56.0",
    "eslint-plugin-react": "^7.33.2",
    "eslint-plugin-react-hooks": "^4.6.0",
    "eslint-plugin-react-refresh": "^0.4.5",
    "vite": "^5.1.0"
  }
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Move React entry file (optional):&lt;br&gt;
By default, Vite expects the entry point of your application to be index.html. If your React project's entry point is index.js or something else, you may need to move it to index.html. Alternatively, you can configure Vite to use a different entry point.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Start the development server:&lt;br&gt;
Now you can start the development server with Vite by running:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm run dev


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This will start a local development server with hot module replacement (HMR) enabled for fast development.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Build your project:
When you're ready to build your project for production, you can run:&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm run build


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This will generate an optimized production build of your React application in the dist directory.&lt;/p&gt;

&lt;p&gt;With these steps, you should have a basic React project set up with Vite, ready for development and production deployment.&lt;br&gt;
You can check the Vite documentation for more advanced configurations and optimizations(&lt;a href="https://vitejs.dev/guide/" rel="noopener noreferrer"&gt;https://vitejs.dev/guide/&lt;/a&gt;).&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
