Socket
Book a DemoInstallSign in
Socket

vite-plugin-swc-react-refresh

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-swc-react-refresh

Use the versatility of SWC for development and the maturity of esbuild for production

latest
Source
npmnpm
Version
2.2.1
Version published
Weekly downloads
579
-12.67%
Maintainers
1
Weekly downloads
 
Created
Source

vite-plugin-swc-react-refresh npm

Use the versatility of SWC for development and the maturity of esbuild for production.

  • ✅ A fast Fast Refresh (~20x faster than Babel)
  • ✅ Compatible with automatic JSX runtime
  • ❌ Don't check for consistent components exports. See this section

Installation

npm i -D vite-plugin-swc-react-refresh

Usage

With the automatic JSX runtime (requires esbuild => 0.14.51):

import { defineConfig } from "vite";
import { swcReactRefresh } from "vite-plugin-swc-react-refresh";

export default defineConfig({
  plugins: [swcReactRefresh()],
  esbuild: { jsx: "automatic" },
});

Without the automatic JSX runtime, but still omitting the React default import:

import { defineConfig } from "vite";
import { swcReactRefresh } from "vite-plugin-swc-react-refresh";

export default defineConfig({
  plugins: [swcReactRefresh()],
  esbuild: { jsxInject: `import React from "react"` },
});

Consistent components exports

For React refresh to work, your file should only export React components. The best explanation I've read is the one from the Gatsby docs.

However, having some components being hot updated and not others is a very frustrating experience as a developer, and I think this rule should be enforced by a linter, so I made an eslint rule to go along with this plugin.

This plugin expects this rule to be respected and will always fast refresh components. If a file export something that is not a React component (TS types are ok), update to this export would not propagate and require a manual reload.

Keywords

vite

FAQs

Package last updated on 02 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts