vite-preset-react is a Vite plugin designed to simplify the setup for React projects by bundling `@vitejs/plugin-react` and providing convenient opinionated options. It aims to reduce boilerplate and offer common optimizations out-of-the-box for React development within the Vite ecosystem. The current stable version is 2.3.0, with releases typically aligning with updates to the underlying `@vitejs/plugin-react` and addressing bug fixes or adding new features. Its key differentiators include options like automatic React DevTools removal for production builds, and flexible injection of the React runtime. This preset streamlines the Vite configuration, making it easier for developers to get started with React without manually configuring multiple plugins or handling complex build optimizations.
npm install vite-preset-reactVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate `vite-preset-react` into `vite.config.ts`, including common options like removing DevTools in production, passing options to the underlying `@vitejs/plugin-react`, and controlling React runtime injection.
Ensure your project's Vite configuration aligns with `@vitejs/plugin-react` if you're interacting with the plugin directly. `vite-preset-react` handles the internal plugin update, but awareness is key if you have deep integrations.
Update your `vite-preset-react` configuration in `vite.config.js` or `vite.config.ts` to use `reactPluginOptions` instead of `reactRefreshOptions`.
Update to version 1.4.2 or newer to mitigate potential console errors when `removeDevtools = true` and DevTools are not active in the browser. For older versions, disable `removeDevtools` during development if you frequently encounter this.
Review the default behavior of `injectReact` (typically `true` in development, `false` in production) and explicitly set it in your configuration if your project has specific requirements for JSX runtime injection. E.g., `injectReact: false`.
Ensure your Vite configuration file (`vite.config.js` or `vite.config.ts`) uses ESM syntax: `import reactPreset from 'vite-preset-react';` instead of `const reactPreset = require('vite-preset-react');`.Rename `reactRefreshOptions` to `reactPluginOptions` in your `vite-preset-react` configuration object within `vite.config.js` or `vite.config.ts`.
Ensure that `reactPreset()` is called and the returned plugin object is added to the `plugins` array in your `vite.config.js` or `vite.config.ts` file, e.g., `plugins: [reactPreset()]`.