Gathering detailed insights and metrics for @vitejs/plugin-react
Gathering detailed insights and metrics for @vitejs/plugin-react
Gathering detailed insights and metrics for @vitejs/plugin-react
Gathering detailed insights and metrics for @vitejs/plugin-react
@vitejs/plugin-react-swc
Speed up your Vite dev server with SWC
@vitejs/plugin-react-refresh
Provides [React Refresh](https://www.npmjs.com/package/react-refresh) support for Vite.
vite-plugin-react-router-generator
A vitejs plugin to use generator react-router
rollup-plugin-react-scoped-css
A rollup plugin designed to allow scoped css to be run in react (Compatible with vite and rollup)
The all-in-one Vite plugin for React projects.
npm install @vitejs/plugin-react
Typescript
Module System
Min. Node Version
Node Version
NPM Version
65.8
Supply Chain
90.1
Quality
93.1
Maintenance
100
Vulnerability
98.6
License
plugin-react@4.4.1
Updated on Apr 19, 2025
plugin-react-swc@3.9.0
Updated on Apr 15, 2025
plugin-react@4.4.0
Updated on Apr 15, 2025
plugin-react-swc@3.9.0-beta.3
Updated on Apr 15, 2025
plugin-react@4.4.0-beta.2
Updated on Apr 15, 2025
plugin-react-oxc@0.1.1
Updated on Apr 10, 2025
TypeScript (65.41%)
JavaScript (23.93%)
CSS (5.96%)
HTML (4.52%)
MDX (0.19%)
Total Downloads
516,914,801
Last Day
1,516,816
Last Week
8,090,109
Last Month
34,527,833
Last Year
293,644,767
MIT License
715 Stars
1,098 Commits
140 Forks
12 Watchers
5 Branches
43 Contributors
Updated on May 08, 2025
Minified
Minified + Gzipped
Latest Version
4.4.1
Package Id
@vitejs/plugin-react@4.4.1
Unpacked Size
57.03 kB
Size
17.36 kB
File Count
9
NPM Version
10.8.2
Node Version
20.19.0
Published on
Apr 19, 2025
Cumulative downloads
Total Downloads
Last Day
46%
1,516,816
Compared to previous day
Last Week
5.2%
8,090,109
Compared to previous week
Last Month
4.8%
34,527,833
Compared to previous month
Last Year
73.9%
293,644,767
Compared to previous year
5
1
2
The default Vite plugin for React projects.
1// vite.config.js 2import { defineConfig } from 'vite' 3import react from '@vitejs/plugin-react' 4 5export default defineConfig({ 6 plugins: [react()], 7})
Includes .js
, .jsx
, .ts
& .tsx
by default. This option can be used to add fast refresh to .mdx
files:
1import { defineConfig } from 'vite' 2import react from '@vitejs/plugin-react' 3import mdx from '@mdx-js/rollup' 4 5export default defineConfig({ 6 plugins: [ 7 { enforce: 'pre', ...mdx() }, 8 react({ include: /\.(mdx|js|jsx|ts|tsx)$/ }), 9 ], 10})
node_modules
are never processed by this plugin (but esbuild will)
Control where the JSX factory is imported from. Default to 'react'
1react({ jsxImportSource: '@emotion/react' })
By default, the plugin uses the automatic JSX runtime. However, if you encounter any issues, you may opt out using the jsxRuntime
option.
1react({ jsxRuntime: 'classic' })
The babel
option lets you add plugins, presets, and other configuration to the Babel transformation performed on each included file.
1react({ 2 babel: { 3 presets: [...], 4 // Your plugins run before any built-in transform (eg: Fast Refresh) 5 plugins: [...], 6 // Use .babelrc files 7 babelrc: true, 8 // Use babel.config.js files 9 configFile: true, 10 } 11})
Note: When not using plugins, only esbuild is used for production builds, resulting in faster builds.
If you are using ES syntax that are still in proposal status (e.g. class properties), you can selectively enable them with the babel.parserOpts.plugins
option:
1react({ 2 babel: { 3 parserOpts: { 4 plugins: ['decorators-legacy'], 5 }, 6 }, 7})
This option does not enable code transformation. That is handled by esbuild.
Note: TypeScript syntax is handled automatically.
Here's the complete list of Babel parser plugins.
The reactRefreshHost
option is only necessary in a module federation context. It enables HMR to work between a remote & host application. In your remote Vite config, you would add your host origin:
1react({ reactRefreshHost: 'http://localhost:3000' })
Under the hood, this simply updates the React Fash Refresh runtime URL from /@react-refresh
to http://localhost:3000/@react-refresh
to ensure there is only one Refresh runtime across the whole application. Note that if you define base
option in the host application, you need to include it in the option, like: http://localhost:3000/{base}
.
In middleware mode, you should make sure your entry index.html
file is transformed by Vite. Here's an example for an Express server:
1app.get('/', async (req, res, next) => {
2 try {
3 let html = fs.readFileSync(path.resolve(root, 'index.html'), 'utf-8')
4
5 // Transform HTML using Vite plugins.
6 html = await viteServer.transformIndexHtml(req.url, html)
7
8 res.send(html)
9 } catch (e) {
10 return next(e)
11 }
12})
Otherwise, you'll probably get this error:
Uncaught Error: @vitejs/plugin-react can't detect preamble. Something is wrong.
For React refresh to work correctly, your file should only export React components. You can find a good explanation in the Gatsby docs.
If an incompatible change in exports is found, the module will be invalidated and HMR will propagate. To make it easier to export simple constants alongside your component, the module is only invalidated when their value changes.
You can catch mistakes and get more detailed warning with this eslint rule.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
30 commit(s) and 12 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 8
Details
Reason
SAST tool is not run on all commits -- score normalized to 7
Details
Reason
3 existing vulnerabilities detected
Details
Reason
Found 12/26 approved changesets -- score normalized to 4
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-04-28
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More