Skip to main content

Vite using SWC

tip

Many applications do not require this plugin. Unless you have been directed here by other documentation, you can probably skip these instructions. See “Should I install the plugin?” for more information.

info

These instructions are for use with @vitejs/plugin-react-swc. If you are using @vitejs/plugin-react you'll need to use the Babel instructions.

SWC PLUGIN SUPPORT IS EXPERIMENTAL

@vitejs/plugin-react-swc v3.1.0 or above is required to support SWC plugins. We recommend using the latest version.

Update your Vite config file to conditionally add the plugin:

vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';
import { pluginoptions } from '@mightymeld/runtime';

const swcPlugins = [];

if (process.env.MIGHTYMELD) {
swcPlugins.push(['@mightymeld/runtime/swc-plugin-mightymeld', pluginoptions()]);
}

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react({
plugins: swcPlugins
})
]
});