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 pageReact CompilerNext pageBrowser Compatibility

      #Improve Build Performance

      Modern.js optimizes build performance by default, but as the project becomes larger, you may encounter some build performance problems.

      This document provides some optional speed-up strategies, developers can choose some of them to improve the build performance.

      📢 Notice

      The strategies in Bundle Size Optimization can also be used to improve build performance, so we won't repeat them here.

      #General optimization strategy

      The following are some general optimization strategies, which can speed up the development build and production build, and some of them also optimize the bundle size.

      #Using Rspack (recommended)

      If you are not using Rspack yet, you can switch to Rspack build mode to improve the build speed by 5~10 times, see Using Rspack for more information.

      #Upgrade Node.js version

      In general, updating Node.js to the latest LTS release will help improve build performance.

      Especially for devices with Apple M1/M2 chips, it is recommended to use at least Node 18.

      Node >= 16 provides Apple Silicon binaries by default, so the performance on M1/M2 models will be greatly improved than Node 14. According to our tests, After switching from Node 14 to Node >= 16, the compilation speed can be improved by more than 100%.

      You can switch to Node 18 by following steps:

      # Install Node v18
      nvm install 18
      
      # switch to Node 18
      nvm use 18
      
      # Set Node 18 as the default version
      nvm default 18
      
      # View Node version
      node -v

      #Development optimization strategies

      The following are strategies for improve build performance in development environment.

      #Adjust Source Map format

      In order to provide a good debugging experience, Modern.js uses the cheap-module-source-map format Source Map by default in the development environment, which is a high-quality Source Map format and will bring certain performance overhead.

      You can improve build speed by adjusting the source map format of your development environment.

      For example to disable Source Map:

      export default {
        tools: {
          bundlerChain(chain, { env }) {
            if (env === 'development') {
              chain.devtool(false);
            }
          },
        },
      };

      Or set the source map format of the development environment to the cheapest eval format:

      export default {
        tools: {
          bundlerChain(chain, { env }) {
            if (env === 'development') {
              chain.devtool('eval');
            }
          },
        },
      };

      For detailed differences between different Source Map formats, see webpack - devtool.

      #Adjust Browserslist for development

      This strategy is similar to "Adjust Browserslist", the difference is that we can set different browserslist for development and production environment, thereby reducing the compilation overhead in the development environment.

      For example, you can add the following config to package.json, which means that only the latest browsers are compatible in the development environment, and the actual browsers are compatible in the production environment:

      {
        "browserslist": {
          "production": [">0.2%", "not dead", "not op_mini all"],
          "development": [
            "last 1 chrome version",
            "last 1 firefox version",
            "last 1 safari version"
          ]
        }
      }

      Note that this strategy can lead to some differences in the build result of development production environment.

      #Production optimization strategies

      The following are strategies for improve build performance in production environment.

      #Disable Source Map

      If your project does not need Source Map in the production, you can turn it off through the sourcemap config to improve the build speed.

      export default {
        output: {
          sourceMap: false,
        },
      };

      See output.sourceMap for details.