The Vite projects using Typescript option use Babel, and using Typescript + SWC option use SWC.
SWC
Advantages:
- Performance: Faster than Babel, ideal for short build times.
- Written in Rust: Leverages efficiency and concurrency.
- Simplicity: Requires less initial configuration.
Disadvantages:
- Limited Ecosystem: Fewer plugins and presets available, at moment.
- Compatibility: Some features may not be fully implemented yet.
- Less Maturity: Smaller community (growing) and documentation compared to Babel.
Project Types:
- New projects prioritizing speed.
- Medium to large applications.
- Situations where simplicity is key.
Babel
Advantages:
- Robust Ecosystem: A fast array of plugins and presets.
- Customization: Detailed configuration for specific needs.
- Maturity and Support: Extensive documentation and active community.
Disadvantages:
- Performance: Generally slower compared to SWC.
- Complex Configuration: Can be complicated for less experienced developers.
Project Types:
- Large and complex projects requiring custom transformations.
- Applications relying on various libraries and tools.
- Situations where compatibility with the latest JavaScript features is critical.
A resume of differences between Babel and SWC according to my point of view and what I understood.
Sources:
- https://swc.rs/docs/getting-started
- https://github.com/vitejs/vite-plugin-react-swc?tab=readme-ov-file
- https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react
1. npm install -D babel-plugin-react-compiler@beta eslint-plugin-react-compiler@beta
2. npm install react-compiler-runtime@beta
3. Edit your vite.config.js file like this:
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
// https://vite.dev/config/
export default defineConfig({
plugins: [
react({
babel: {
plugins: [['babel-plugin-react-compiler', { target: '18' }]],
},
}),
],
});
4. Build your app and run it. (npm run build and then npm run preview).
Videos
The Vite projects using Typescript option use Babel, and using Typescript + SWC option use SWC.
SWC
Advantages:
- Performance: Faster than Babel, ideal for short build times.
- Written in Rust: Leverages efficiency and concurrency.
- Simplicity: Requires less initial configuration.
Disadvantages:
- Limited Ecosystem: Fewer plugins and presets available, at moment.
- Compatibility: Some features may not be fully implemented yet.
- Less Maturity: Smaller community (growing) and documentation compared to Babel.
Project Types:
- New projects prioritizing speed.
- Medium to large applications.
- Situations where simplicity is key.
Babel
Advantages:
- Robust Ecosystem: A fast array of plugins and presets.
- Customization: Detailed configuration for specific needs.
- Maturity and Support: Extensive documentation and active community.
Disadvantages:
- Performance: Generally slower compared to SWC.
- Complex Configuration: Can be complicated for less experienced developers.
Project Types:
- Large and complex projects requiring custom transformations.
- Applications relying on various libraries and tools.
- Situations where compatibility with the latest JavaScript features is critical.
A resume of differences between Babel and SWC according to my point of view and what I understood.
Sources:
- https://swc.rs/docs/getting-started
- https://github.com/vitejs/vite-plugin-react-swc?tab=readme-ov-file
- https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react
The + SWC options use SWC for transpilation instead of Babel, which is generally faster than the non-SWC option, but might (in rare cases) have bugs. (For React, this really means whether to choose this or this Vite plugin.)
I would select a + SWC option.
I have a pretty large codebase in a nx monorepo. Currently using vite with swc.
Wanted to switch the react compiler on, but it looks like I'd have to go back to Babel, and the lining is not even there yet (e.g. would be nice to get warnings when a dev is using a memo for no reason).
Am I missing something? Anyone here using the react compiler successfully?
And.. What is the deal with oxc? The ecosystem feels so fragmented..
Does Vite recommend starting new projects with typescript + swc??
Is it completely stable?
Any thoughts are appreciated :)
» npm install @vitejs/plugin-react-swc