Which is Better React Development Tools?
@vitejs/plugin-react vs @craco/craco
1 Year
@vitejs/plugin-react@craco/cracoSimilar Packages:
What's React Development Tools?

The npm packages @craco/craco and @vitejs/plugin-react are tools designed to enhance the development experience for React applications. @craco/craco is a configuration layer for Create React App (CRA) that allows developers to customize the CRA setup without ejecting, providing flexibility in managing configurations such as Babel, Webpack, and more. On the other hand, @vitejs/plugin-react is a plugin for Vite, a modern build tool that offers fast development and optimized production builds. This plugin enables React-specific features in Vite, such as Fast Refresh for a better development experience and support for JSX and TypeScript. Both tools cater to different build systems and workflows, making them suitable for various project requirements.

NPM Package Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
@vitejs/plugin-react5,049,35858837.3 kB1210 days agoMIT
@craco/craco388,0627,427140 kB472 years agoApache-2.0
Feature Comparison: @vitejs/plugin-react vs @craco/craco

Customization

  • @vitejs/plugin-react: @vitejs/plugin-react integrates seamlessly with Vite, enabling the use of React features such as Fast Refresh and JSX transformations. It allows for minimal configuration while taking advantage of Vite's performance optimizations.
  • @craco/craco: @craco/craco allows extensive customization of the Create React App configuration without the need to eject. This means you can modify Webpack, Babel, ESLint, and other settings while still benefiting from CRA's built-in features and updates.

Development Speed

  • @vitejs/plugin-react: Vite is known for its lightning-fast development server and hot module replacement (HMR), which drastically reduces the time it takes to see changes in the browser. This plugin enhances that experience for React applications, making development faster and more enjoyable.
  • @craco/craco: While @craco/craco does not inherently improve build speed, it allows developers to maintain a familiar CRA environment while customizing it to their needs, which can lead to more efficient development workflows without the overhead of ejecting.

Ecosystem Compatibility

  • @vitejs/plugin-react: @vitejs/plugin-react is tailored for projects using Vite, which is a modern alternative to traditional build tools. It is compatible with Vite's ecosystem, allowing developers to utilize Vite's plugins and features effectively.
  • @craco/craco: @craco/craco is specifically designed for projects that start with Create React App, making it compatible with the CRA ecosystem and its conventions. It ensures that developers can use CRA's features while extending its capabilities.

Learning Curve

  • @vitejs/plugin-react: Vite has a relatively low learning curve, especially for developers familiar with modern JavaScript tooling. The integration of React features through this plugin is straightforward, making it accessible for new users.
  • @craco/craco: Developers familiar with Create React App will find @craco/craco easy to adopt, as it builds upon existing CRA knowledge. The learning curve is minimal for those already accustomed to CRA's structure and conventions.

Community and Support

  • @vitejs/plugin-react: Vite has rapidly gained popularity, leading to a vibrant community and extensive documentation. The @vitejs/plugin-react plugin is well-supported, with resources available for developers to maximize its potential.
  • @craco/craco: @craco/craco has a growing community, primarily due to its association with Create React App. It benefits from community support and documentation that helps developers troubleshoot and implement custom configurations.
How to Choose: @vitejs/plugin-react vs @craco/craco
  • @vitejs/plugin-react: Choose @vitejs/plugin-react if you are using Vite as your build tool and want to leverage its speed and modern features. This is suitable for new projects or those looking to migrate from CRA to a more performant setup.
  • @craco/craco: Choose @craco/craco if you are working with Create React App and need to customize your configuration without ejecting. It is ideal for projects that require specific Babel or Webpack settings while maintaining the CRA ecosystem.
README for @vitejs/plugin-react

@vitejs/plugin-react npm

The default Vite plugin for React projects.

// vite.config.js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

export default defineConfig({
  plugins: [react()],
})

Options

include/exclude

Includes .js, .jsx, .ts & .tsx by default. This option can be used to add fast refresh to .mdx files:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import mdx from '@mdx-js/rollup'

export default defineConfig({
  plugins: [
    { enforce: 'pre', ...mdx() },
    react({ include: /\.(mdx|js|jsx|ts|tsx)$/ }),
  ],
})

node_modules are never processed by this plugin (but esbuild will)

jsxImportSource

Control where the JSX factory is imported from. Default to 'react'

react({ jsxImportSource: '@emotion/react' })

jsxRuntime

By default, the plugin uses the automatic JSX runtime. However, if you encounter any issues, you may opt out using the jsxRuntime option.

react({ jsxRuntime: 'classic' })

babel

The babel option lets you add plugins, presets, and other configuration to the Babel transformation performed on each included file.

react({
  babel: {
    presets: [...],
    // Your plugins run before any built-in transform (eg: Fast Refresh)
    plugins: [...],
    // Use .babelrc files
    babelrc: true,
    // Use babel.config.js files
    configFile: true,
  }
})

Note: When not using plugins, only esbuild is used for production builds, resulting in faster builds.

Proposed syntax

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:

react({
  babel: {
    parserOpts: {
      plugins: ['decorators-legacy'],
    },
  },
})

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.

Middleware mode

In middleware mode, you should make sure your entry index.html file is transformed by Vite. Here's an example for an Express server:

app.get('/', async (req, res, next) => {
  try {
    let html = fs.readFileSync(path.resolve(root, 'index.html'), 'utf-8')

    // Transform HTML using Vite plugins.
    html = await viteServer.transformIndexHtml(req.url, html)

    res.send(html)
  } catch (e) {
    return next(e)
  }
})

Otherwise, you'll probably get this error:

Uncaught Error: @vitejs/plugin-react can't detect preamble. Something is wrong.

Consistent components exports

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.