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 uses Babel (or oxc when used in rolldown-vite) for Fast Refresh
- @vitejs/plugin-react-swc uses SWC for Fast Refresh
The React Compiler is enabled on this template. See this documentation for more information.
Note: This will impact Vite dev & build performances.
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
export default defineConfig([
globalIgnores(["dist"]),
{
files: ["**/*.{ts,tsx}"],
extends: [
// Other configs...
// Remove tseslint.configs.recommended and replace with this
tseslint.configs.recommendedTypeChecked,
// Alternatively, use this for stricter rules
tseslint.configs.strictTypeChecked,
// Optionally, add this for stylistic rules
tseslint.configs.stylisticTypeChecked,
// Other configs...
],
languageOptions: {
parserOptions: {
project: ["./tsconfig.node.json", "./tsconfig.app.json"],
tsconfigRootDir: import.meta.dirname,
},
// other options...
},
},
]);You can also install eslint-plugin-react-x and eslint-plugin-react-dom for React-specific lint rules:
// eslint.config.js
import reactX from "eslint-plugin-react-x";
import reactDom from "eslint-plugin-react-dom";
export default defineConfig([
globalIgnores(["dist"]),
{
files: ["**/*.{ts,tsx}"],
extends: [
// Other configs...
// Enable lint rules for React
reactX.configs["recommended-typescript"],
// Enable lint rules for React DOM
reactDom.configs.recommended,
],
languageOptions: {
parserOptions: {
project: ["./tsconfig.node.json", "./tsconfig.app.json"],
tsconfigRootDir: import.meta.dirname,
},
// other options...
},
},
]);Prettier automatically formats your code so that it follows a consistent style.
- Open VS Code.
- Go to Extensions using the Extensions icon in the left sidebar.
- Search for Prettier - Code formatter.
- Install the extension by Prettier (
prettier.io).
- Open the Command Palette with
Ctrl + Shift + P(Windows/Linux) orCmd + Shift + P(Mac). - Search for Preferences: Open User Settings (JSON) and select it.
- Add the following configuration to your
settings.jsonfile:
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}- Save the file.
If you already have other settings in
settings.json, don't replace the entire file. Add these settings alongside your existing configuration.
To automatically format your code whenever you save a file:
- Open Settings using the gear icon in the bottom-left corner of VS Code.
- Search for Format On Save.
- Find Editor: Format On Save.
- Enable the checkbox.
Now, whenever you save a JavaScript or TypeScript file, VS Code will automatically format it using Prettier.