Simple React App using Vite and TypeScript
nvm
is node.js version manager.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
Close and reopen terminal.
Install via nvm
:
nvm install v20.15.1
Make sure you do not have default node set:
nvm unalias default
Activate node 20.15.1:
nvm use 20.15.1
Configure npm
(Node Package Manager) to save versions of packages in packages.json
. This way you can have the same stable environment on all development machines:
nvm use 20.15.1
npm config set save=true
npm config set save-exact=true
source configure.sh
Start dev
server:
npm run dev
Open application in default browser:
open http://localhost:5173
Build (builds the app in ./dist
):
npm run build
Preview build (serves ./dist
on http://localhost:4173):
npm run preview
npm create vite@latest . -- --template react-ts
The react
template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
HMR === Hot Module Reloading
Currently, two official plugins are available, that can be used in vite.config.js
:
- @vitejs/plugin-react uses Babel for Fast Refresh (used by default)
- @vitejs/plugin-react-swc uses SWC for Fast Refresh
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
- Configure the top-level
parserOptions
property like this:
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
- Replace
tseslint.configs.recommended
totseslint.configs.recommendedTypeChecked
ortseslint.configs.strictTypeChecked
- Optionally add
...tseslint.configs.stylisticTypeChecked
- Install eslint-plugin-react and update the config:
// eslint.config.js
import react from 'eslint-plugin-react'
export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
})