The Rsbuild-based library development tool.
—
Command-line interface providing development workflow tools including build, development server, inspection, and Module Federation support. The CLI is the primary interface for most Rslib operations.
Main CLI entry point that processes command line arguments and routes to appropriate commands.
/**
* Main CLI entry point that processes command line arguments
* Routes to appropriate commands based on arguments
* Supports: build, dev, inspect, mf-dev, init
*/
function runCli(): void;Available Commands:
rslib build - Build the libraryrslib dev - Build in watch moderslib inspect - Inspect build configurationrslib mf-dev - Start Module Federation dev serverrslib init - Initialize new projectUsage Examples:
# Build library
npx rslib build
# Build with watch mode
npx rslib dev
# Build specific libraries
npx rslib build --lib esm,cjs
# Inspect configuration
npx rslib inspect --verbose
# Start Module Federation dev server
npx rslib mf-devInitializes CLI environment, sets up process handlers, and displays startup information.
/**
* Initializes CLI environment and sets up process handlers
* Sets up graceful shutdown, error handling, and startup information
*/
function prepareCli(): void;This function is typically called internally before CLI operations to ensure proper environment setup.
Base options available across all CLI commands:
interface CommonOptions {
/** Project root directory */
root?: string;
/** Configuration file path */
config?: string;
/** Environment files directory */
envDir?: string;
/** Environment mode */
envMode?: string;
/** Library selection (array of library IDs or formats) */
lib?: string[];
}Options specific to build operations:
interface BuildOptions extends CommonOptions {
/** Enable watch mode for automatic rebuilds */
watch?: boolean;
}Usage Examples:
# Build with custom config
rslib build --config ./custom.config.js
# Build with watch mode
rslib build --watch
# Build specific libraries
rslib build --lib esm --lib cjs
# Build with custom root
rslib build --root ./packages/my-libOptions for configuration inspection:
interface InspectOptions extends CommonOptions {
/** Build mode (development or production) */
mode?: RsbuildMode;
/** Output directory for inspection results */
output?: string;
/** Enable verbose output */
verbose?: boolean;
}Usage Examples:
# Basic inspection
rslib inspect
# Inspect with verbose output
rslib inspect --verbose
# Inspect production mode
rslib inspect --mode production
# Inspect with custom output
rslib inspect --output ./inspect-resultsWhile CLI commands are typically run from the command line, you can also invoke CLI functionality programmatically:
import { runCli, prepareCli } from "@rslib/core";
// Set up CLI environment
prepareCli();
// Run CLI with programmatic arguments
process.argv = ["node", "rslib", "build", "--watch"];
runCli();The CLI respects several environment variables:
NODE_ENV - Sets the build environmentRSLIB_LOG_LEVEL - Controls logging verbosityRSLIB_CONFIG - Default configuration file pathThe CLI automatically discovers configuration files in this order:
--config CLI argumentrslib.config.jsrslib.config.mjsrslib.config.tsrslib.config.mtsCompiles the library according to the configuration:
rslib build [options]
Options:
--watch, -w Watch for changes and rebuild
--config, -c <file> Configuration file path
--root <dir> Project root directory
--lib <libs...> Build specific libraries
--env-mode <mode> Environment mode
--env-dir <dir> Environment files directoryBuilds the library in watch mode (alias for build --watch):
rslib dev [options]
# Equivalent to:
rslib build --watch [options]Analyzes and outputs the build configuration:
rslib inspect [options]
Options:
--mode <mode> Build mode (development|production)
--output, -o <dir> Output directory
--verbose, -v Verbose output
--config, -c <file> Configuration file path
--root <dir> Project root directory
--lib <libs...> Inspect specific librariesStarts a development server for Module Federation builds:
rslib mf-dev [options]
Options:
--config, -c <file> Configuration file path
--root <dir> Project root directory
--lib <libs...> Serve specific libraries
--env-mode <mode> Environment modeInitializes a new Rslib project with interactive setup:
rslib init [project-name]
Options:
[project-name] Name of the project to create
# Interactive project setup
rslib init my-library
# Create project in current directory
rslib initThe init command provides an interactive CLI to create a new Rslib project with:
The CLI provides comprehensive error handling and reporting:
The CLI includes built-in logging capabilities:
const logger: Logger;Log Levels:
debug - Detailed debugging informationinfo - General informationwarn - Warning messageserror - Error messagesEnvironment Variables:
DEBUG=rslib - Enable debug loggingRSLIB_LOG_LEVEL=debug - Set specific log levelUsage:
# Enable debug logging
DEBUG=rslib rslib build
# Set log level
RSLIB_LOG_LEVEL=verbose rslib buildInstall with Tessl CLI
npx tessl i tessl/npm-rslib--core