Rslib
website·Indexed 35 days ago
https://lib.rsbuild.dev/A library development tool based on Rsbuild that provides a simple way to create JavaScript libraries for browser and Node.js targets. It supports TypeScript, various output formats (ESM, CJS, UMD), and integrates with frameworks like React, Vue, Svelte, Solid, and ReactLynx. Rslib includes features for handling third-party dependencies, declaration files, CSS processing, and WebAssembly, and offers migration paths from tsup and tsc.
What's inside Rslib
- Rslib is a library development tool based on Rsbuild, designed for building JavaScript libraries such as utility libraries, UI component libraries, CLIs, and agent applications. It leverages the Rspack and webpack ecosystems, allowing developers to use Rsbuild plugins and loaders. Key capabilities include a unified build pipeline for compiling JavaScript, transforming framework syntax, generating declarations, and processing static assets in a single pass.
Overview of Rslib for library development
Rslib is a library development tool based on Rsbuild and Rspack. It is designed to simplify the creation of JavaScript and UI component libraries by providing integrated tooling for building, debugging, documentation, and testing.
Key advantages include:
- High-Quality ESM Output: Optimizes webpack's ESM output to reduce redundant runtime code and improve tree-shaking for consumers.
- Performance: Powered by Rspack and integrates Rust-based tools like SWC and Lightning CSS for fast build speeds.
- Ecosystem Compatibility: Supports Rsbuild, Rspack, and webpack plugins.
- Framework Agnostic: Supports React, Vue, Svelte, Solid, and other frameworks via plugins.
- Flexible Distribution: Provides configurable build outputs for different runtimes and distribution methods.
Overview of Rslib for library development
Rslib is a library development tool based on Rspack and Rsbuild, developed by the ByteDance Web Infra Team. It is designed to unify library building with application building configurations, allowing developers to reuse the Rspack/Rsbuild ecosystem while addressing common library-specific pain points such as multi-format output, declaration file bundling, and style processing.Overview of Rslib
Rslib is a library development tool based on Rsbuild designed to simplify the creation of JavaScript libraries, providing an intuitive way to build and package them.Overview of the Rstack JavaScript toolchain
Rstack is a fast, unified JavaScript toolchain designed for developers and AI agents. It consists of several Rust-based tools aimed at improving build performance and developer experience:Understand Rslib configuration structure
Rslib configuration is divided into two types of options:
- Lib configurations: Define library outputs, including output formats, structures, and syntax targets.
- Rsbuild configurations: Control underlying compilation and build behavior, such as module resolution and source processing.
The
libfield is an optional array of objects. Each object represents a specific output. Configurations placed inside alibitem apply only to that output, while configurations placed outside thelibfield are top-level and shared across all outputs. Rslib merges top-level configurations with eachlibitem.export default { // Top-level: shared across all outputs syntax: 'es2021', lib: [ { format: 'esm', // This output inherits syntax: 'es2021' }, { format: 'cjs', syntax: 'es2020', // Overrides top-level for this output only }, ], };Default third-party dependency handling in Rslib
By default, Rslib does not bundle third-party dependencies listed underdependencies,optionalDependencies, andpeerDependenciesinpackage.jsonwhen generating CJS or ESM outputs. This reduces the package size since these dependencies are expected to be installed by the end-user. To force a dependency to be bundled, move it fromdependenciestodevDependencies.Configure basic executable generation with experiments.exe
Settingexperiments.exetotrueenables executable generation using the current host's platform, architecture, and Node.js version as the template. The executable is output to the current JavaScript output directory.export default { lib: [ { experiments: { exe: true, }, }, ], };Use @rslib/core for build capabilities
@rslib/core is the core package for Rslib. It provides the necessary CLI commands and build capabilities powered by Rsbuild to develop and bundle libraries.Configure Rspack options within Rslib
Rspack-specific options can be adjusted using thetools.rspackconfiguration property. For other Rslib and Rsbuild specific options, refer to the general Configuration overview.Configure Node.js SEA options via experiments.exe.seaOptions
The
seaOptionsobject is passed directly to the Node.js SEA configuration.Constraints:
useSnapshotcannot be used withformat: 'esm'.- If a target differs from the host platform/architecture, Rslib automatically disables
useSnapshotanduseCodeCachefor compatibility.
Available Options:
disableExperimentalSEAWarning(boolean, default:true)useSnapshot(boolean, default:false)useCodeCache(boolean, default:false)execArgv(string[])execArgvExtension('none' | 'env' | 'cli', default: 'env')assets(Record<string, string>)
export default { lib: [ { experiments: { exe: { seaOptions: { useCodeCache: true, execArgv: ['--no-warnings'], }, }, }, }, ], };Use Lightning CSS for transformation
Rslib uses Rspack's built-inlightningcss-loaderto transform CSS. It automatically reads the project'ssyntaxconfiguration to convert modern CSS features into syntax compatible with the target browsers.