Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
@vitejs/plugin-react-swc
Advanced tools
@vitejs/plugin-react-swc is a Vite plugin that enables the use of React with the SWC (Speedy Web Compiler) compiler. This plugin provides faster build times and improved performance for React applications by leveraging SWC's capabilities.
Basic Setup
This code demonstrates how to include the @vitejs/plugin-react-swc plugin in a Vite configuration file. This setup allows Vite to use SWC for compiling React code.
```json
{
"plugins": [
"@vitejs/plugin-react-swc"
]
}
```
Custom SWC Configuration
This code sample shows how to customize the SWC configuration within the Vite plugin. It configures SWC to parse TypeScript and use the automatic JSX runtime.
```json
{
"plugins": [
["@vitejs/plugin-react-swc", {
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true
},
"transform": {
"react": {
"runtime": "automatic"
}
}
}
}]
]
}
```
@vitejs/plugin-react is another Vite plugin for React, but it uses Babel instead of SWC for compilation. While it is more mature and has broader support for various Babel plugins, it may not offer the same performance benefits as SWC.
vite-plugin-swc is a general-purpose SWC plugin for Vite that can be used with various frameworks, including React. It provides similar performance benefits as @vitejs/plugin-react-swc but requires more manual configuration for React-specific features.
Speed up your Vite dev server with SWC
npm i -D @vitejs/plugin-react-swc
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
export default defineConfig({
plugins: [react()],
});
This plugin is only used in development and aims to be kept simple to enable good performances and be transpiler agnostic. Here is the list of non-configurable options that impact runtime behaviour:
jsx runtime
is always automatic
target
is es2020
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.
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
3.0.0
This is plugin is now stable! 🎉
To migrate from vite-plugin-swc-react-refresh
, see the 3.0.0-beta.0
changelog.
FAQs
Speed up your Vite dev server with SWC
The npm package @vitejs/plugin-react-swc receives a total of 1,199,312 weekly downloads. As such, @vitejs/plugin-react-swc popularity was classified as popular.
We found that @vitejs/plugin-react-swc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
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.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.