logo
  • Guide
  • Config
  • Plugin
  • API
  • Examples
  • Community
  • Modern.js 2.x Docs
  • English
    • 简体中文
    • English
    • Start
      Introduction
      Quick Start
      Upgrading
      Glossary
      Tech Stack
      Core Concept
      Page Entry
      Build Engine
      Web Server
      Basic Features
      Routes
      Routing
      Config Routes
      Data Solution
      Data Fetching
      Data Writing
      Data Caching
      Rendering
      Server-Side Rendering
      Streaming SSR
      Rendering Cache
      Static Site Generation
      Render Preprocessing
      Styling
      Styling
      Use CSS Modules
      Using CSS-in-JS
      Using Tailwind CSS
      HTML Template
      Import Static Assets
      Import JSON Files
      Import SVG Assets
      Import Wasm Assets
      Debug
      Data Mocking
      Network Proxy
      Using Rsdoctor
      Using Storybook
      Testing
      Playwright
      Vitest
      Jest
      Cypress
      Path Alias
      Environment Variables
      Output Files
      Deploy Application
      Advanced Features
      Using Rspack
      Using BFF
      Basic Usage
      Runtime Framework
      Extend BFF Server
      Extend Request SDK
      File Upload
      Cross-Project Invocation
      Optimize Page Performance
      Code Splitting
      Inline Static Assets
      Bundle Size Optimization
      React Compiler
      Improve Build Performance
      Browser Compatibility
      Low-Level Tools
      Source Code Build Mode
      Server Monitor
      Monitors
      Logs Events
      Metrics Events
      Internationalization
      Basic Concepts
      Quick Start
      Configuration
      Locale Detection
      Resource Loading
      Routing Integration
      API Reference
      Advanced Usage
      Best Practices
      Custom Web Server
      Topic Detail
      Module Federation
      Introduction
      Getting Started
      Application-Level Modules
      Server-Side Rendering
      Deployment
      Integrating Internationalization
      FAQ
      Dependencies FAQ
      CLI FAQ
      Build FAQ
      HMR FAQ
      Deprecated
      📝 Edit this page
      Previous pageBundle Size OptimizationNext pageImprove Build Performance

      #React Compiler

      The React Compiler is an experimental compiler introduced in React 19 that can automatically optimize your React code.

      Before starting to use the React Compiler, it is recommended to read the React Compiler documentation to understand its features, current status, and usage.

      #How to Use

      The steps to use the React Compiler in Modern.js are as follows:

      1. Modern.js does not officially support React 19 yet, but you can install react-compiler-runtime@rc in React 17 or 18 projects to allow the compiled code to run on versions before 19.

      2. Currently, the React Compiler only provides a Babel plugin, so you need to install babel-plugin-react-compiler.

      3. Register the Babel plugin in your Modern.js configuration file:

      modern.config.ts
      import { appTools, defineConfig } from '@modern-js/app-tools';
      
      export default defineConfig({
        tools: {
          babel(_, { addPlugins }) {
            addPlugins([
              [
                'babel-plugin-react-compiler',
                {
                  target: '18',
                },
              ],
            ]);
          },
        },
        plugins: [appTools()],
      });

      For detailed code, you can refer to the Modern.js & React Compiler example project