• Stars
    star
    822
  • Rank 55,485 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 3 years ago
  • Updated 4 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
67,211
star
2

awesome-vite

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

docs-cn

Chinese translation of vite.dev
Vue
838
star
4

vite-plugin-react

The all-in-one Vite plugin for React projects.
TypeScript
574
star
5

create-vite-app

Create a Vite-powered app in seconds!
JavaScript
573
star
6

vite-plugin-vue2

Vite plugin for Vue 2.7
TypeScript
539
star
7

vite-plugin-vue

Vite Vue Plugins
TypeScript
456
star
8

vite-plugin-react-pages

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

vite-plugin-react-refresh

React Fast Refresh plugin for Vite
TypeScript
304
star
10

vite-plugin-basic-ssl

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

vite-ecosystem-ci

Vite Ecosystem CI
TypeScript
228
star
12

rfcs

RFCs for substantial changes to Vite core
109
star
13

docs-ko

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

vite-ts-monorepo-rfc

An RFC for better support for TS monorepos in Vite
TypeScript
98
star
15

vite-benchmark

Benchmark tool for vitejs/vite
JavaScript
79
star
16

docs-ja

Japanese translation of vitejs.dev
Vue
76
star
17

vite-plugin-vue2-jsx

Vite plugin for Vue 2.7 JSX support
TypeScript
58
star
18

release-scripts

@vitejs release scripts
TypeScript
44
star
19

docs-pt

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

docs-es

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

rfcs-bot

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

.github

10
star
23

docs-de

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