Giter Site home page Giter Site logo

devathimahesh / vite-plugin-swc-react-refresh Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vitejs/vite-plugin-react-swc

0.0 1.0 0.0 60 KB

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

License: MIT License

JavaScript 75.96% TypeScript 24.04%

vite-plugin-swc-react-refresh's Introduction

vite-plugin-swc-react-refresh npm

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

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.

vite-plugin-swc-react-refresh's People

Contributors

arnaudbarre avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.