React Ts Starter screenshot

React Ts Starter

Author Avatar Theme by Codinggarden
Updated: 10 Oct 2024
214 Stars

A bare-bones vite + react + typescript starter template with eslint + prettier, vitest + @testing-library and react-router

Categories

Overview:

The Vite + React + TypeScript Starter is a setup that combines Vite, React, and TypeScript to provide a streamlined development environment for creating web applications. With this setup, developers can benefit from the fast, modern build tooling provided by Vite, the power and flexibility of React, and the type safety of TypeScript.

Features:

  • Vite: Vite is a next-generation build tool that provides fast and optimized builds for modern web applications. It offers an efficient development server, instant hot module replacement (HMR), and a lean build output.
  • React: This setup utilizes React, a popular JavaScript library for building user interfaces. React provides a component-based approach to building UI elements, making it easier to create and manage complex user interfaces.
  • TypeScript: TypeScript is a strongly-typed superset of JavaScript that adds static type checking to JavaScript code. By using TypeScript, developers can catch errors early during the development process and ensure better code quality and maintainability.
  • ESLint, typescript-eslint, eslint-airbnb-config, prettier: This setup includes a combination of linting tools and configurations. ESLint, typescript-eslint, eslint-airbnb-config, and Prettier work together to enforce coding styles, catch potential bugs, and improve code consistency and readability.
  • Vitest, JSDOM, @testing-library/react: The setup includes Vitest, JSDOM, and @testing-library/react to facilitate testing in the development process. Vitest is a testing framework specifically designed for Vite, while JSDOM provides a virtual DOM implementation for testing purposes. @testing-library/react is a popular testing library that helps in writing clean and efficient tests for React components.
  • React Router v6: The setup includes React Router v6, which is a flexible and efficient routing library for React applications. It allows developers to handle navigation and routing within their applications, enabling them to create single-page applications with ease.

Installation:

To set up the Vite + React + TypeScript Starter, follow these steps:

  1. Start by creating a new project directory and navigate to it:
mkdir my-app
cd my-app
  1. Initialize a new project using npm or yarn:
npm init -y
# or
yarn init -y
  1. Install the necessary dependencies:
npm install --save-dev vite eslint typescript eslint-airbnb-config prettier vitest jsdom @testing-library/react react-router
# or
yarn add --dev vite eslint typescript eslint-airbnb-config prettier vitest jsdom @testing-library/react react-router
  1. Create a vite.config.js file in the project root and add the following content:
module.exports = {
  root: "./src",
  build: {
    outDir: "../dist",
    rollupOptions: {
      input: "/main.tsx",
    },
  },
};
  1. Create a tsconfig.json file in the project root and add the following content:
{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "jsx": "react",
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true
  },
  "exclude": ["node_modules"]
}
  1. Create a .eslintrc file in the project root and add the following content:
{
  "extends": [
    "eslint:recommended",
    "plugin:react/recommended",
    "airbnb",
    "prettier"
  ],
  "plugins": ["react"],
  "parserOptions": {
    "ecmaVersion": 2020,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "env": {
    "browser": true,
    "es6": true,
    "node": true
  },
  "rules": {
    "react/prop-types": "off"
  }
}
  1. Create a .prettierrc file in the project root and add the following content:
{
  "semi": true,
  "trailingComma": "es5",
  "singleQuote": true,
  "printWidth": 100
}
  1. You’re ready to start developing your Vite + React + TypeScript application! You can create React components in the src directory and use the Vite development server to preview your changes.

Summary:

The Vite + React + TypeScript Starter provides developers with a powerful and efficient setup for creating web applications. By combining Vite, React, TypeScript, and various other tools and libraries, this setup offers fast builds, type safety, linting, testing, and routing capabilities. With a straightforward installation process, developers can quickly set up their development environment and start building modern and maintainable web applications.