1.0.0 • Published 2 years ago

@lucasols/vite-plugin-swc-react v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

vite-plugin-swc-react

This is a fork of https://github.com/ArnaudBarre/vite-plugin-swc-react-refresh

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

Installation

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

Usage

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

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

JSX Runtime

This plugin is only used in development, and esbuild (which doesn't support the automatic JSX runtime) will be used by Vite for bundling. However, you can omit the default React import with the esbuild.jsxInject Vite option.

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.

1.0.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.2.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago