Home / Articles / Vite + React from zero, with React Compiler enabled early

This article is published in English.

Vite + React from zero, with React Compiler enabled early

Scaffold with Vite, read the entrypoint, and turn on React Compiler before the first feature lands.

1732 words

React’s original pitch was predictable UI over changing data. The modern starter path is Vite for fast local feedback, and—when you opt in—React Compiler to automate memoization that used to be hand-written.

What we use (and skip)

Vite + React + TypeScript as the base. No CRA. React Compiler turned on deliberately so you can see its effect from the first components.

Prerequisite: Node.js

Install a current Node LTS, confirm node and npm (or pnpm) on PATH, then scaffold:

// The old way — you manually keep the screen in sync every time the data changes
const badge = document.querySelector('#unread-badge');
badge.textContent = count;
if (count === 0) {
  badge.style.display = 'none';
} else {
  badge.style.display = 'block';
}

Read the folder structure

Know where index.html, src/main.tsx, and App live before changing tooling:

// The React way — you simply declare "for this state, the screen looks like this"
function UnreadBadge({ count }: { count: number }) {
  if (count === 0) return null;
  return <span className="badge">{count}</span>;
}

Entry point dissection

The entry mounts the root and pulls global CSS. Keep it boring; feature code belongs in components.

node -v
corepack enable

Turn on React Compiler

Add the compiler plugin to the build config so Babel/SWC integration matches the docs for your Vite version:

npm install -g pnpm
pnpm create vite@latest restart-react --template react-ts

Confirm it is active

Use the documented checks or a small component that would otherwise need useMemo/memo, and verify compiler output or tooling indicators:

cd restart-react
pnpm install
pnpm dev
restart-react/
├── index.html          ← the single HTML file the app mounts into
├── package.json        ← dependencies and scripts
├── tsconfig.json       ← TypeScript config
├── vite.config.ts      ← Vite config (we'll edit this shortly)
└── src/
    ├── main.tsx        ← the app's entry point
    ├── App.tsx         ← the top-level component
    ├── App.css
    └── index.css

First feature without fighting the tool

// src/main.tsx
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.tsx'

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <App />
  </StrictMode>,
)
pnpm install -D babel-plugin-react-compiler@latest @rolldown/plugin-babel

Wrap-up

// vite.config.ts (before)
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [react()],
});
// vite.config.ts (after)
import { defineConfig } from 'vite';
import react, { reactCompilerPreset } from '@vitejs/plugin-react';
import babel from '@rolldown/plugin-babel';

export default defineConfig({
  plugins: [
    react(),
    babel({
      presets: [reactCompilerPreset()],
    }),
  ],
});

You now have a Vite React app with compiler support wired early—ideal for a series that assumes automatic memoization rather than bolting it on later. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name. Keep fixtures green, measure each stage separately, and refuse to ship on vibes alone when the next release can reintroduce the same silent failure mode under a new name.