Everything you need to kick off your next Vite + React web app!
Built with type safety, scalability, and developer experience in mind. A batteries included Vite + React template.
A more detailed list of the included packages can be found in the Installed Packages section. Packages not shown above include Devtools, ui helper libraries, and eslint plugins/configs.
If you'd like to use the included Dockerfile then Docker is required as well:
Getting started is a simple as cloning the repository
git clone git@github.com:RicardoValdovinos/vite-react-boilerplate.git
Changing into the new directory
cd vite-react-boilerplate
Removing the .git folder (and any additional files, folders or dependencies you may not need)
rm -rf .git
Installing dependencies
pnpm install
And running the setup script (initializes git repository and husky and installs playwright)
pnpm run setup
Congrats! You're ready to starting working on that new project!
If you'd rather run the commands above in one go, check out the command below:
git clone git@github.com:RicardoValdovinos/vite-react-boilerplate.git &&\
cd vite-react-boilerplate &&\
rm -rf .git &&\
pnpm install &&\
pnpm run setup
Note: This project comes with two git hooks added by husky. A prepare-commit-msg hook to run the Commitizen cli for those nice commit messages and a commit-msg hook to run Commitlint on the message itself. Commitlint will ensure the commit message follows the Conventional Commits specification (it will if you used commitizen).
If you wish to remove any hooks, simply delete the corresponding file in the .husky directory.
This boilerplate project does not include a demo. At most, a few utilities (types, devtools, initial home page routes) are included. There is no glue to get in your way when trying to modify the template.
Due to empty directories not being included in git commits, placeholder README files have been added to these empty directories. These README files contain simple descriptions about how the different directories in the accompanying folder structure may be used. As an example check out the recommended component organizational structure as well as the recommended folder structure.
Faker is included to encourage more isolated testing and allow for rapid development of demos and MVPs. However, please make note that, due to a bug, importing Faker from the main package (without a locale) will result in the entire Faker lib being imported causing bundle sizes to increase up to 2+ MB. Instead prefer localized imports as shown below.
// import { faker } from '@faker-js/faker';
import { faker } from '@faker-js/faker/locale/en'; // prefer localization when possible
The imported lib will instead be around 600 KB. Nonetheless, Faker should NOT be used in production and instead be limited to testing and demos.
Unit testing is handled by React Testing Library and Vitest while End-to-End (E2E) Testing is conducted by Playwright.
If you'd like to run all tests, Unit and E2E alike, execute the following command:
pnpm run test
When running unit test scripts, it is assumed that unit tests will be colocated with the source files. Take a look at the placeholder README file in src/components
for an example.
If you'd like to execute unit tests specifically, the below command will execute vitest:
pnpm run test:unit
If instead you are interested in coverage reporting, run:
pnpm run test:unit:coverage
All unit tests run in watch mode by default. If you'd like to disable watch mode, change the package.json test scripts with the following
before:
"scripts": {
"test:unit": "vitest src/",
"test:unit:coverage": "vitest --coverage src/"
}
After:
"scripts": {
"test:unit": "vitest run src/",
"test:unit:coverage": "vitest run --coverage src/"
}
Note: Faker is included to provide mock data. See the Important Note section for crucial details regarding this package. Specifically, point 3.
Running E2E tests use a similar syntax to running unit tests:
pnpm run test:e2e
If you wish to see the reports, run:
pnpm run test:e2e:report
Instructions are provided for deploying both with and without Docker. Both options still require a platform to host the application.
Deploying is as easy as running
pnpm run build
and pointing your web server to the generated index.html
file found at dist/index.html
A Dockerfile with an NGINX base image is also provided for quick and easy deployments. Simply execute the following commands:
pnpm run build
docker build . -t <container_name>
docker build . -t todo-app
docker run -p <port_number>:80 <container_name>
docker run -p 8080:80 todo-app
Due to the vast array of tools, opinions, requirements and preferences a CI template is not included in this project.
This project includes a set of Devtools. Some are additional package dependencies whereas others come built-in to the packages themselves.
A set of utility components are provided in src/components/utils/development-tools/
. These wrapper components check whether the application is running in development or production mode and render the component or null respectively. In other words, you can confidently use them during development without having to worry about them showing up for end users in production.
TanStack Query Devtools are ready to go out of the box. The development vs. production rendering mechanism is built into the devtools. If you do wish to render the devtools in production you can freely do so by following the TanStack Query Devtools documentation. The devtools component can be found in src/App.tsx
.
When running the application in development mode you can find the TanStack Query Devtools icon in the bottom left corner of the page sporting the React Query Logo.
TanStack Router Devtools, however, utilizes its respective utility component in this project. The initial setup has been taken care of but if you wish to modify or remove the component, have a look in src/App.tsx
.
The TanStack Router Devtools icon can be found in the bottom right corner of the page denoted by the vertically stacked "TANSTACK ROUTER" logo.
The above components, along with their imports, are commented out to start.
TanStack Table Devtools Documentation is, at the time of writing this, non-existent. Having said that, usage is similar to the other TanStack devtools. A utility component restricting the devtools to development builds has been provided. The difference in comparison to the other TanStack devtools is the lack of floating mode. Instead, the Devtools are rendered as a component within the actual TanStack Table you define. An additional caveat being that the DevTools component (built-in and provided utility alike) require a table prop from the useReactTable()
hook. In other words, if you have multiple tables, each table must have its own Devtools component. Check the simplified code below.
function Table(): FunctionComponent {
/* some code */
const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
});
return (
<>
{/* table code */}
<TanStackTableDevelopmentTools table={table} />
</>
)
}
React Hook Form DevTools icon can be recognized in the top right corner of the page by the pink React Hook Form clipboard logo. A utility component has also provided. Like the TanStack Table Devtools component above, a prop must be passed from a specific hook. In this case, it is the control prop from the useForm()
hook. Similar to TanStack Table, use of React Hook Form DevTools requires the component be added to each unique form. More information can be found in the React Hook Form DevTools documentation.
To reiterate, if you wish to restrict the Devtools to development builds use the provided components found at src/components/utils/development-tools
instead of the built-in components from their respective modules.
Zustand provides a built-in devtools middleware for use with Redux DevTools.
A simplified list can be found in the Overview section.