<> Start your React project with Vite following code best practices (TypeScript, Linting, testing, CI/CD…)
Overview
This product analysis discusses a Vite template that can be used to create a new project. The template provides a starting point for developers using React.js without a complete framework like Next.js, Remix, or Gatsby. It includes various features such as GitHub Action Workflows, linting, testing with Jest and React Testing Library, end-to-end testing with Cypress, and more. The installation process is straightforward, with instructions on updating project meta-information and running the app.
Features
- GitHub repository creation: The template can be used to create a project on GitHub by using the “Use this template” button and cloning the newly created repository.
- Local project creation: Alternatively, developers can create a local project using degit.
- Project meta-information update: Developers are guided on updating the package.json file with proper values for the name, author, and license properties. They are also instructed to remove the private property if they plan to publish the app as an npm package. Additionally, the author in the LICENSE file, title in index.html, and favicon in the public directory should be changed.
- App setup clean-up: Developers are advised to clean up the README.md file after setting up the app.
- Unit testing: The template includes support for running unit tests with Jest and React Testing Library.
- End-to-end testing: End-to-end tests can be conducted with Cypress by choosing either the npm run cy:open or npm run cy:run options.
- Linting: Linting can be performed using the npm run lint command, and lint issues can be fixed with npm run lint:fix.
- Tech stack: The template is built using TypeScript and is already configured with ESLint and Prettier with Codely’s configuration. It also includes Jest with React Testing Library for unit tests, Cypress with Testing Library for end-to-end tests, GitHub Action Workflows for running tests and linting on push, Makefile for standardizing project running, Sass for enhanced CSS, and editorconfig for sharing IDE config.
Installation
To install the Vite template, follow these steps:
Create your project based on this template:
a) If you want to create a GitHub repository, use the GitHub “Use this template” button and clone your newly created repository.
b) If you prefer to create a local project, use degit.
Update your project meta-information:
- Update the package.json file by specifying proper values for the name, author, and license properties.
- Remove the private property if you plan to publish the app as an npm package.
- Change the author in the LICENSE file.
- Change the title in index.html.
- Replace the favicon in the public directory.
- Clean up the README.md file.
Run your app:
- Move to your project root directory by running
cd my-app
. - Install all the project dependencies by running
npm install
. - Start the development server on localhost:3000 by running
npm start
.
Testing:
- Run unit tests with Jest and React Testing Library by running
npm run test
. - For end-to-end tests with Cypress, choose one of the following options:
- Open Cypress in dev mode by running
npm run cy:open
. - Execute Cypress in CLI by running
npm run cy:run
.
Linting:
- Run linting with ESLint by running
npm run lint
. - Fix lint issues by running
npm run lint:fix
.
Summary
The Vite template provides a simple and efficient starting point for developers using React.js without a complete framework. It includes various features such as GitHub Action Workflows, linting, unit testing with Jest and React Testing Library, end-to-end testing with Cypress, and more. The installation process involves creating a project based on the template, updating project meta-information, and running the app. Overall, the template offers a streamlined development experience for React projects.