Rsbuild

website·Indexed 34 days ago

https://v1.rsbuild.rs

A high-performance build tool powered by Rspack. It provides out-of-the-box support for TypeScript, CSS, HTML, and WebAssembly, with dedicated integration for frameworks like React, Vue, Preact, Svelte, and Solid. Rsbuild includes a built-in dev server, support for Module Federation, Server-Side Rendering (SSR), and advanced optimization features such as code splitting and Hot Module Replacement (HMR).

Tokens
107.1K
Snippets
746
Records
872
Agent score
63%

What's inside Rsbuild

  1. Overview of Rsbuild CLI commands

    Rsbuild provides a lightweight CLI for managing the build lifecycle. The primary commands include dev for development, build for production, preview for local testing of production builds, and inspect for debugging configurations.
    # View all available commands
    npx rsbuild -h
  2. Overview of Rsbuild Dev Server

    Rsbuild includes a built-in development server activated by running rsbuild dev or rsbuild preview. It provides essential development features including page preview, routing, and Hot Module Replacement (HMR).
  3. Overview of Rsbuild

    Rsbuild is a modern, TypeScript-friendly build tool built on top of Rspack. It is designed to provide the performance of Rust-based bundling while eliminating the configuration complexity typically associated with webpack. It serves two primary roles: as a lightweight build tool for quickly setting up Client-Side Rendering (CSR) applications, and as a shared infrastructure providing JavaScript and Plugin APIs for other frameworks and tools.
  4. Overview of Rsbuild plugin hooks

    Rsbuild provides a variety of plugin hooks categorized by their execution context. These hooks allow developers to modify configurations, intercept the build process, and manage server lifecycles.

    Common Hooks: Used for general configuration and lifecycle events (e.g., modifyRsbuildConfig, modifyRspackConfig, onExit). Dev Hooks: Triggered during rsbuild dev or rsbuild.startDevServer() (e.g., onBeforeStartDevServer, onAfterDevCompile). Build Hooks: Triggered during rsbuild build or rsbuild.build() (e.g., onBeforeBuild, onAfterBuild). Preview Hooks: Triggered during rsbuild preview or rsbuild.preview() (e.g., onBeforeStartProdServer).

  5. Overview of Rsbuild

    Rsbuild is a high-performance build tool powered by Rspack. It is designed to provide an out-of-the-box development experience with sensible defaults while leveraging a Rust-based architecture for speed. It is framework-agnostic and supports React, Vue, Svelte, Solid, and Preact via plugins. Key built-in features include support for TypeScript, JSX, Sass, Less, CSS Modules, Wasm, Module Federation, image compression, type checking, PostCSS, and Lightning CSS.
  6. Overview of Module Federation in Rsbuild

    Module Federation is an architectural pattern that allows multiple JavaScript applications (micro-frontends) to share code and resources at runtime without recompiling the entire application. It is used to reduce code duplication, improve maintainability, and optimize application performance by enabling independent teams to work on different parts of a large-scale web application.
  7. Use Lightning CSS for transformation and prefixing

    Rsbuild uses Rspack's built-in lightningcss-loader by default to transform CSS. It automatically reads the project's browserslist configuration to provide vendor prefixing (e.g., -webkit-, -moz-) and downgrades modern CSS syntax (like nesting and custom media queries) for browser compatibility. Customization is available via the tools.lightningcssLoader option.
  8. Capture Rspack build performance profiles

    To capture a performance profile of the Rspack core, set the RSPACK_PROFILE environment variable to OVERVIEW.

    After the process finishes, Rsbuild creates a folder named .rspack-profile-${timestamp}-${pid} containing a rspack.pftrace file (or trace.json in versions < 1.4.0). This file can be uploaded and viewed at ui.perfetto.dev.

    {
      "scripts": {
        "dev:profile": "cross-env RSPACK_PROFILE=OVERVIEW rsbuild dev",
        "build:profile": "cross-env RSPACK_PROFILE=OVERVIEW rsbuild build"
      },
      "devDependencies": {
        "cross-env": "^7.0.0"
      }
    }
  9. Understand the relationship between Rsbuild and Rspack

    Rspack is the underlying bundler that powers Rsbuild. While Rspack is a low-level bundler requiring manual configuration of loaders and plugins (similar to webpack), Rsbuild is a high-level build tool designed to provide a zero-config experience with built-in best practices, official plugins, and a more powerful CLI and dev server.
  10. Customize CssExtractRspackPlugin options

    Use tools.cssExtract.pluginOptions to pass configuration to the CssExtractRspackPlugin. Common options include ignoreOrder to disable warnings about conflicting CSS order, and filename/chunkFilename to define the output paths for CSS files. By default, Rsbuild sets ignoreOrder: true and derives filenames from output.distPath and output.filename.
    export default {
      tools: {
        cssExtract: {
          pluginOptions: {
            ignoreOrder: false,
            filename: 'static/css/[name].css',
            chunkFilename: 'static/css/async/[name].css',
          },
        },
      },
    };
  11. CSS processing and styling in Rsbuild

    Rsbuild uses Lightning CSS by default to downgrade CSS syntax. It supports several styling workflows:

    • CSS Modules: Files matching *.module.* are compiled as CSS Modules by default. Type definitions can be generated using rsbuild-plugin-typed-css-modules.
    • Minification: CSS minification is enabled by default in production builds.
    • Inlining: CSS can be inlined into JavaScript files via output.injectStyles.
    • Post-processing: PostCSS transformation can be configured via tools.postcss.
  12. Access and use the EnvironmentContext object

    The EnvironmentContext is a read-only object providing metadata about a specific build environment. It can be accessed via Rsbuild Plugin hooks (through the environment or environments parameters) or via the Environment API using environments.context.
    type EnvironmentContext = {
      name: string; // Unique name of the environment (corresponds to config key)
      browserslist: string[]; // Browserslist configuration for this environment
      config: NormalizedEnvironmentConfig; // Normalized Rsbuild config for this environment
      distPath: string; // Absolute path of the output directory
      entry: RsbuildEntry; // Entry object from source.entry
      htmlPaths: Record<string, string>; // Map of entry names to relative HTML paths in dist
      tsconfigPath?: string; // Absolute path to tsconfig.json, if it exists
      manifest?: Record<string, unknown> | ManifestData; // Manifest data (requires output.manifest enabled)
      webSocketToken: string; // WebSocket auth token (dev mode only, empty in production)
    };