• Stars
    star
    667
  • Rank 65,165 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 2 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Speed up your Vite dev server with SWC

@vitejs/plugin-react-swc npm

Speed up your Vite dev server with SWC

Installation

npm i -D @vitejs/plugin-react-swc

Usage

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";

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

Caveats

This plugin has limited options to enable good performances and be transpiler agnostic. Here is the list of non-configurable options that impact runtime behaviour:

  • useDefineForClassFields is always activated, as this matches the current ECMAScript spec
  • jsx runtime is always automatic
  • In development:
    • esbuild is disabled, so the esbuild configuration has no effect
    • target is es2020
    • JS files are not transformed
    • tsconfig is not resolved, so properties other than the ones listed above behaves like TS defaults

Options

jsxImportSource

Control where the JSX factory is imported from.

react({ jsxImportSource: "@emotion/react" });

tsDecorators

Enable TypeScript decorators. Requires experimentalDecorators in tsconfig.

react({ tsDecorators: true });

plugins

Use SWC plugins. Enable SWC at build time.

react({ plugins: [["@swc/plugin-styled-components", {}]] });

Consistent components exports

For React refresh to work correctly, your file should only export React components. The best explanation I've read is the one from 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.

Migrating from vite-plugin-swc-react-refresh

The documentation for the previous version of the plugin is available in the v2 branch

To migrate, see this changelog

More Repositories

1

vite

Next generation frontend tooling. It's fast!
TypeScript
64,165
star
2

awesome-vite

⚡️ A curated list of awesome things related to Vite.js
JavaScript
13,046
star
3

docs-cn

Chinese translation of vitejs.dev
TypeScript
831
star
4

create-vite-app

Create a Vite-powered app in seconds!
JavaScript
572
star
5

vite-plugin-vue2

Vite plugin for Vue 2.7
TypeScript
515
star
6

vite-plugin-react

The all-in-one Vite plugin for React projects.
TypeScript
461
star
7

vite-plugin-react-pages

A vite framework for building react app. Especially suitable for document site and demos/playgrounds of react components.
TypeScript
409
star
8

vite-plugin-vue

Vite Vue Plugins
TypeScript
371
star
9

vite-plugin-react-refresh

React Fast Refresh plugin for Vite
TypeScript
303
star
10

vite-plugin-basic-ssl

Basic https setup using an automatically generated self-signed certificate
TypeScript
230
star
11

vite-ecosystem-ci

Vite Ecosystem CI
TypeScript
219
star
12

rfcs

RFCs for substantial changes to Vite core
109
star
13

docs-ko

ViteJS 한글 공식 문서 (Korean translation of vitejs.dev)
TypeScript
101
star
14

vite-benchmark

Benchmark tool for vitejs/vite
JavaScript
79
star
15

docs-ja

Japanese translation of vitejs.dev
TypeScript
72
star
16

vite-plugin-vue2-jsx

Vite plugin for Vue 2.7 JSX support
TypeScript
54
star
17

release-scripts

@vitejs release scripts
TypeScript
35
star
18

docs-pt

Portuguese translation of vitejs.dev | Documentação da Vite em Português. 🇦🇴 🇧🇷 🇵🇹
29
star
19

docs-es

Traducción al español de la documentación de vitejs.dev
JavaScript
16
star
20

rfcs-bot

Automation of RFCs creation for vitejs/rfcs
TypeScript
13
star
21

.github

7
star
22

docs-de

🇩🇪 German translation of vitejs.dev | Die deutsche Übersetzung von vitejs.dev.
TypeScript
4
star