This is a project starter for building scalable and maintainable web applications with React, TypeScript, and Tailwind. It implements the following tools:
- Static analysis: TypeScript, ESLint, Prettier
- Testing: Vitest, Testing Library, Mock Service Worker
- Build process: Vite, PostCSS
- Get the repository to start your new project.
- Run
npm installin your project directory to install the dependencies. - Run
npm run devto start the development server. - Start building your application in
src/App.tsx.
Note: The project requires Node.js version 18+ or 20+.
After you clone or download the repository, navigate to the project's folder:
cd starter-app-react-ts-tailwindThen install the dependencies:
npm installIf you are using Visual Studio Code, you will be prompted to install several recommended extensions after opening the project:
- Tailwind CSS IntelliSense
- Prettier - Code formatter
- Formatting Toggle
- ESLint
- Vitest
- EditorConfig for VS Code
To start developing your React/TypeScript application, go to src/App.tsx. You can use the Tailwind classes right away.
To check the formatting with Prettier (without modifying the files):
npm run format:checkTo actually format (modify) the files with Prettier:
npm run formatTo lint the files using ESLint:
npm run lintTo statically check types with TypeScript:
npm run typesA sample unit test for the App component has been included. You can find it in src/App.test.tsx.
You can start describing the network using the MSW request handlers in src/tests/mocks/handlers.ts. The MSW/Node.js integration module (src/tests/mocks/server.ts) is already started in vitest.setup.ts.
To run all tests and view the results in the terminal:
npm run testTo run all tests and view the results in the browser:
npm run test:uiTo run all tests and generate a test coverage report:
npm run coverageTo run Vite's development server:
npm run devTo preview the production build locally (after building the project with the build script):
npm run previewTo run the TypeScript compiler and Vite's build process:
npm run buildTailwind CSS is installed as a PostCSS plugin (see postcss.config.js) and configured to process the contents of the root index.html and all .ts/.tsx files in the src directory. No customizations are provided by default. You can change the configuration in tailwind.config.js.
Any additional plugins (like tailwindcss-typography, tailwindcss-forms, tailwindcss-aspect-ratio, or tailwindcss-container-queries) can also be added in tailwind.config.js.
Tailwind's base styles and the other two layers are included by default (see src/index.css).
Prettier uses the default configuration. It also has the prettier-plugin-tailwindcss plugin enabled to automatically sort classes based on Tailwind's recommended class order. You can change the configuration in .prettierrc.
Ignored files (not to be formatted) can be specified in .prettierignore. According to its documentation, Prettier also respects the .gitignore configuration and ignores node_modules/.
By default, ESLint uses the recommended configuration and the following plugins with their respective recommended configurations:
- typescript-eslint
- eslint-plugin-react
- eslint-plugin-react-hooks
- eslint-plugin-jsx-a11y
- eslint-plugin-react-refresh
You can see the details and tweak the configuration to your needs in eslint.config.js.
By default, all .ts/.tsx files in the src directory are included for analysis. Strict type checking and several linting options are enabled to catch unused local variables or function parameters and to prevent unsafe switch cases. The configuration ensures that the code complies with the JavaScript features supported by ES2020.
The compiler won't emit JavaScript files, leaving that responsibility to Vite.
You can change the configuration in tsconfig.app.json.
By default, Vitest is configured to use the @vitejs/plugin-react plugin to handle React's JSX syntax. It also uses jsdom as its testing environment. You can change the configuration in vitest.config.ts.
The MSW/Node.js integration module (src/tests/mocks/server.ts) is handled in vitest.setup.ts.
By default, Vite is configured to use the @vitejs/plugin-react plugin to handle React's JSX syntax. You can change the configuration in vite.config.ts.
PostCSS can be configured in postcss.config.js. By default, it uses Tailwind CSS (configured in tailwind.config.js) to generate CSS and Autoprefixer (which uses the recommended default Browserslist configuration from .browserslistrc) to ensure cross-browser support by automatically adding necessary CSS prefixes.
To keep line endings consistent across different development environments, EditorConfig is set to use LF. You can change the configuration in .editorconfig.
Visual Studio Code has some workspace settings added by default. These set Prettier as the default formatter and make the editor always open .css files in Tailwind CSS mode. You can change these settings in .vscode/setttings.json.
You can also add the following to your global VS Code user settings to automatically format files with Prettier:
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnType": trueLine endings are set to LF in .gitattributes. Files to be ignored by Git can be specified in .gitignore.
This project is licensed under the MIT License.