Vite helps us quickly create a React app. Run the following command:
npm create vite@latest
- Project name:
frontend-app-react-ts
- Select
react
andtypescript
.
Open the project folder in Visual Studio Code using the command:
code .
Run the following command to install the necessary node modules:
npm i
Install the essential packages for your project:
npm i @hookform/resolvers axios chart.js moment react-chartjs-2 react-hook-form react-hot-toast react-icons react-router-dom yup
- Visit the Tailwind CSS Installation Guide.
- Under Framework Guides, select Vite.
- Copy and run the following commands:
npm install -D tailwindcss postcss autoprefixer npx tailwindcss init -p
- Open the
tailwind.config.js
file and replace its contents with:export default { content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"], theme: { extend: {}, }, plugins: [], }
- Open the
index.css
file located atsrc/index.css
:- Remove all existing CSS.
- Delete the
app.css
file and any related imports fromapp.tsx
. - Add the following lines to
index.css
:@tailwind base; @tailwind components; @tailwind utilities;
- Open the
App.tsx
file. - Remove all the existing code and replace it with:
import React from 'react'; const App = () => { return ( <div className='bg-red-500 p-8'> App </div> ); }; export default App;
open file package.json
"scripts": {
"dev": "vite --port=3000",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
}
Run the following command to start the development server:
npm run dev
Install these extensions for an improved development experience:
- Tailwind CSS IntelliSense
- ES7+ React/Redux/React-Native Snippets
- Prettier - Code Formatter