/react-ts-template

Opinionated template for frontend React TypeScript projects with Vite, ESLint, Prettier, Vitetest, and more. Includes a README template

Primary LanguageTypeScriptMIT LicenseMIT

React TS Template

Opinionated template for frontend React TypeScript projects with Vite, ESLint, Prettier, Vitetest, and more packages. This template aims to speed up the initial configuration and boilerplate for new projects, while providing integration with a range of modern tooling. This repo also includes a React starter app using Bootstrap Components and React Router 6.

Template includes:

  • React 17: frontend framework
  • Vite: frontend build tool and dev server, configured in ./vite.config.ts
  • TypeScript 4.7: types for js. Configured in ./tsconfig.json
  • SASS: CSS preprocessor
  • ESLint: Linter/code analyzer for TypeScript. Configured in ./.eslintrc.cjs with rules from AirBnB and SonarJS
  • Stylelint: Linter/code analyzer for SCSS. Configured in ./.stylelintrc.cjs
  • Prettier: Formatter. Configured in ./.prettierrc.cjs
  • Vitest: unit testing framework. Configured in ./vite.config.ts > test
  • Storybook: view, document and test individual components and pages. Configured in ./.storybook/main.cjs
  • unplugin-auto-import: global imports. Configured in ./vite.config.ts > Plugins > AutoImport
  • pnpm: configuration for the pnpm package manager for better performance, lockfiles and monorepo support. See steps below if you wish to use a different package manager.
  • npm scripts - run with pnpm run <script>:
    • dev - starts a dev environment on localhost with Hot Module Reloading (automatically updates when source code changes)
    • dev:https - starts a dev environment on localhost over https (requires local development certificates to be generated, or use vite-plugin-basic-ssl to auto generate certs)
    • build - compile production source code to ./dist
    • preview - after build, preview on localhost
    • lint - evaluate ESLint rules against source code
    • format - format source code with prettier and try to fix any ESLint errors
    • test:run - run tests using Vitest
    • test:ui - run tests and display a UI on localhost
    • test - run unit tests in watch mode (automatically reruns tests when source code changes)
    • coverage - run coverage tests and output results to ./coverage
    • storybook - launch Storybook to view, document and test components and pages
  • Husky: pre-commit Git hooks to lint, format and run tests. Configured in ./.husky
  • Renovate: GitHub bot for automatic dependency updates. Configured in ./renovate.json
  • GitHub Actions: GitHub CI/CD pipeline. Configured in ./.github/workflows
  • Starter React app with Bootstrap 5 and React Router 6
  • See the Project Structure

Complete the configuration checklist below and remove from the README once complete.

TODO

↑ Remove everything above once setup is complete. ↑


project_title

project_description


CI Commit Renovate


Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Development

About The Project

About text.

Goals

  • Stuff to do

Getting Started

Prerequisites

  • Install node for the version in .nvmrc or use nvm:

    nvm install && nvm use
  • Install the pnpm package manager. Use corepack for automatic installation, which is an experimental node feature that must be enabled using:

    corepack enable

Installation

  • Clone the repo:

    git clone https://github.com/Tim-W-James/repo_name.git
  • Install dependencies with pnpm:

    pnpm i

Usage

  • Build to ./dist and preview:

    pnpm build
    pnpm preview

Development

  • Ensure you have Git Hooks enabled (should run automatically after pnpm i):

    npx husky install
  • Start a development environment:

    pnpm dev

Testing

  • Run unit tests in watch mode (automatically reruns tests when source code changes):

    pnpm test
  • Run coverage tests and output results to ./coverage:

    pnpm coverage
  • View and test individual components or pages:

    pnpm storybook

Code Style

Project Structure

  • Source Code: ./src
  • Unit Tests: place tests adjacent to source code
  • Storybook Stories: place stories adjacent to source code
  • SCSS Styling:
    • Use index.scss for globals
    • Place page or component specific styles adjacent to source code, using scoped .modules
  • Global TypeScript Types: ./types
  • Web Accessible Files (robots.txt, manifest.json, etc.): ./public
  • Site Assets (favicon.svg, images, etc.): ./public/assets. Has alias @assets

Define path alias in ./tsconfig.paths.json.

I recommend using VSCode file nesting for a cleaner file tree.

Documentation

  • Document code with JSDoc

  • Document components or pages with Storybook and run with:

    pnpm storybook

↑ Back to Top ↑