React / JSX
React / JSX
What is React
What is .jsx
What is Vite
1
2
3
4
5
6
7
8
9
10
11
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.
New
Frameworks and Build Tools
What is a Framework?
In general, a framework is a structured set of tools that provides a foundation for creating software
- The tools for the framework are usually in the form of libraries
- There are usually accepted conventions for how to use the framework, and where your code “fits in”
In web development, a framework is a pre-built structure of code that provides tools, libraries, and conventions to create and organise web applications efficiently and in a consistent way. You can always add new libraries / plugins, and make changes to the setup but you should be able to generate usable output with the base set of tools and associated commands.
As frameworks are templates of sorts they are usually installed via command-line eg. npm create vite@latest my-app for Vite / React app in JavaScript or django-admin startproject myproject for a Django project in Python. These commands usually create the directory and file structure of the project. Not all frameworks have these commands, or as rigid of a directory structure, but it is very common.
[!NOTE] Not all frameworks are full-stack, sometimes they only cover part of the project and you may need to interleave different frameworks in order to “create your stack”
What is a Build Tool?
A build tool is software that automates the process of preparing your code for production. It takes your source code and transforms it into optimised files that browsers can efficiently run. Build tools are essential for modern web development because they bridge the gap between developer-friendly code and production-ready, optimised files.
Uses of Build Tools
Development
- Provide a development server to serve files locally, via
localhost - Provide
Hot Module Replacement(HMR) where updates in the code show up in browser without full refresh - Provide
source mapswhich allow you to debug transpiled code by mapping back to original source
Transpilation
- Transform
TypeScripttoJavaScript - Process
JSXintoJavaScript - Convert modern
JavaScript(ES6+) to older versions for browser compatibility - Convert
Sass/SCSStoCSS
Bundling
- Combine multiple files into fewer files
- Resolve
import/exportstatements - Create optimised bundles for faster loading
Optimisation
Minification- Remove whitespace, comments, and shorten variable namesTree shaking- Remove unused codeCode splitting- Break large bundles into smaller chunksAsset optimisation- Compress images, fonts, and other assets
Common Build Tools:
Webpack- Powerful and highly configurable bundler that is used by many frameworksParcel- Zero-configuration build toolesbuild- Extremely fastJavaScriptbundlerRollup- Focused onESmodules and “tree shaking”Vite- Commonly used build tool that usesesbuildandRollupunder the hood
Example Frameworks / Build Tools for Web Development
Vite
Vite is a build tool, and also a development server that handles routing and makes use of HMR. It allows you to bundle code for production via npm run build, and handles minification and optimisation of the built files. Another common use is the transpilation of .ts => .js and .jsx => .js
Vitewith vanillaJavaScriptnpm create vite@latest my-appVitewithReactnpm create vite@latest my-app -- --template react
Svelte
Svelte is a frontend framework that includes a compiler for .svelte files and has its own “reactivity” system, it often uses Vite for the development server / HMR and build tools (bundling, minification)
npm create vite@latest my-app -- --template svelte
[!NOTE] You can also try
SvelteKitwhich is a full-stack framework forSveltewhich usesViteby default
Next.js
Next.js is a full-stack framework built on React that includes a build tool (usually Webpack), the React UI library and tools for routing and makes use of Hot Module Replacement (HMR). It can be thought of as a “meta-framework”, or a framework on top of another framework.
npx create-next-app@latest my-app
Vue.js
Vue.js is a frontend framework with a component-based architecture and reactivity system. It can be used as both a library and framework depending on setup
npm create vue@latest my-app
Angular
Angular is a comprehensive frontend framework with built-in routing, HTTP client, and uses TypeScript by default
npm install -g @angular/cli
ng new my-app
React
One of the most commonly mentioned things in web development is React, and it is often thought of as a framework. In reality it is best thought of as a UI library, or a set of tools for creating reactive elements, or a reactive DOM, for your site.
[!NOTE] Whilst it is not the point of this section on frameworks, in simple terms elements in the
DOM“react” to changes in the underlying data, and theDOMonly re-renders elements that have been changed. It usesdiffingto achieve this, which is comparing two versions of something, here theDOMand theVirtual DOM, and finding the differences between them.
[!NOTE] This document focuses on frontend frameworks and build tools. Backend frameworks (
Express.js,Django,Flask) andCSSframeworks (Tailwind CSS,Bootstrap) are also important even if they haven’t been touched upon here.