Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions Vite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# [Vite Crash Course – Frontend Build Tool](https://www.youtube.com/watch?v=do62-z3z6FM&ab_channel=freeCodeCamp.org)

## Key Notes

- Vite means fast in French.
- Founder of Vite (2019) is Evan, also founder of Vue.js (2014).
- Improves the development and feedback cycle so that we can see changes immediately.
- Provides the initial code required for web development.

## Requirements and Initial Setup

- Node, npm

```bash
npm create vite@latest
npm install && npm run dev
```

The application runs at http://localhost:5173/

## Understanding Folder Structure Created by Vite

- `index.html` – Starting point of the project.
- `src/` – Contains source code and assets.
- `package.json` – Includes all dependencies and npm scripts.
- `vite.config.js` – Vite configuration and list of plugins.

![Foolder Structure](screenshots/Folders.png)

## Experience Fast Development

- Vite uses Hot Module Replacement (HMR).
- Replaces only the part/component that got updated instead of updating the entire application.
- Example: I created a component and placed it in `App.jsx` and it showed instantly.

## Handling Static Assets with Vite

- Vite will hash or optimize the size of images while building. Images should be present in the `src` folder and imported using a relative path.

![Building images](screenshots/Build.png)

- All images and files have a hash value at the end and reduced size inside the `dist` folder.
- Files you do not want optimized should be kept in `public` or outside the `src` folder.
- Example: `vite.svg` is placed outside of `src` and in the `dist` folder it does not have the hashed at the end.

![Building images](screenshots/public_folder.png)

## Use Environment Variables in Vite

- Use a `.env` file and all variables should start with `VITE_`.

## Build for Production

- `"build": "vite build"` → `npm run build`
- Creates a `dist` folder with all required files (some compressed) for production.
- `"preview": "vite preview"` → `npm run preview`
- Boots up a local static server from the `dist` folder and runs on port 4173.

## How Flexible is Vite – Configuration and Options

- `vite.config.js` contains all configurations.
- You can add additional plugins to the Vite application. Example:
- Install QR code plugin: `npm install --save-dev vite-plugin-qrcode`
- Use it in `vite.config.js`.
- After running `npm run dev`, you will see the plugin in action.

![QR code running](screenshots/Plugin.png)

## Why Vite?

- Based on esbuild, rollup.js, and Rolldown (Rust-based), making the application very fast in rendering content.
24 changes: 24 additions & 0 deletions Vite/Vite_JS/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
12 changes: 12 additions & 0 deletions Vite/Vite_JS/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# React + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.
33 changes: 33 additions & 0 deletions Vite/Vite_JS/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'

export default [
{ ignores: ['dist'] },
{
files: ['**/*.{js,jsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
},
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...js.configs.recommended.rules,
...reactHooks.configs.recommended.rules,
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
]
13 changes: 13 additions & 0 deletions Vite/Vite_JS/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
Loading