This repository demonstrates some customizations to Vite's React + Typescript template, improving the ESLint configuration and adding Prettier for formatting.
This repo can be used in two ways:
- As a template, either creating a new repo from this template on GitHub, or just copying it. After doing so, update the versions of all dependencies;
npm-check-updates
is useful for this. - Creating a new project with
npm create vite <project name> -- --template react-ts
, then manually applying the customizations from this repository.
All changes can be seen in this GitHub diff view.
- ESLint is configured more strictly with type-aware linting (in
.eslintrc.cjs
), following the suggestions in the Vite template's README - see commita86d4dd
.- ESLint's
parserOptions
are added. plugin:@typescript-eslint/recommended
is replaced withplugin:@typescript-eslint/recommended-type-checked
.eslint-plugin-react
is installed, addingplugin:react/recommended
andplugin:react/jsx-runtime
.
- ESLint's
- ESLint is configured to automatically detect the current React version - see commit
c082caa
. - Prettier is added and configured for code formatting - see commit
897f0ad
. Prettier has also been run on all files in this repo. This repo doesn't include any settings to run Prettier automatically on saving a file - set that up in your editor of choice.prettier
,eslint-config-prettier
, andeslint-plugin-prettier
are added asdevDependencies
inpackage.json
."plugin:prettier/recommended"
is added to the end of theextends
array ineslintrc.cjs
."prettier/prettier": "warn"
is added as an ESLint rule ineslintrc.cjs
..prettierc.cjs
is added with Prettier settings, though this isn't necessary; trailing commas and an increased line length are just my personal preferences.
- The
dev
andpreview
scripts inpackage.json
have the--host
option added, which enables them to work in GitHub Codespaces - see commitd81cf0a
. I found this solution from vitejs/vite#12561.