CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-rslib--core

The Rsbuild-based library development tool.

Pending
Overview
Eval results
Files

cli.mddocs/

CLI Operations

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.

Capabilities

CLI Entry Point

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 library
  • rslib dev - Build in watch mode
  • rslib inspect - Inspect build configuration
  • rslib mf-dev - Start Module Federation dev server
  • rslib init - Initialize new project

Usage 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-dev

CLI Preparation

Initializes 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.

CLI Options

Common Options

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[];
}

Build Options

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-lib

Inspect Options

Options 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-results

CLI Integration

Programmatic CLI Usage

While 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();

Environment Variables

The CLI respects several environment variables:

  • NODE_ENV - Sets the build environment
  • RSLIB_LOG_LEVEL - Controls logging verbosity
  • RSLIB_CONFIG - Default configuration file path

Configuration File Discovery

The CLI automatically discovers configuration files in this order:

  1. --config CLI argument
  2. rslib.config.js
  3. rslib.config.mjs
  4. rslib.config.ts
  5. rslib.config.mts

CLI Commands Detail

Build Command

Compiles 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 directory

Dev Command

Builds the library in watch mode (alias for build --watch):

rslib dev [options]

# Equivalent to:
rslib build --watch [options]

Inspect Command

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 libraries

Module Federation Dev Command

Starts 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 mode

Init Command

Initializes 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 init

The init command provides an interactive CLI to create a new Rslib project with:

  • Project template selection (Node.js, React, Vue, etc.)
  • TypeScript/JavaScript choice
  • Package manager selection
  • Output format configuration

CLI Error Handling

The CLI provides comprehensive error handling and reporting:

  • Configuration Errors: Clear messages for invalid configurations
  • Build Errors: Detailed compilation error reporting with file locations
  • Validation Errors: Type checking and validation error details
  • Process Errors: Graceful handling of interruptions and cleanup

Logging and Debug

The CLI includes built-in logging capabilities:

const logger: Logger;

Log Levels:

  • debug - Detailed debugging information
  • info - General information
  • warn - Warning messages
  • error - Error messages

Environment Variables:

  • DEBUG=rslib - Enable debug logging
  • RSLIB_LOG_LEVEL=debug - Set specific log level

Usage:

# Enable debug logging
DEBUG=rslib rslib build

# Set log level
RSLIB_LOG_LEVEL=verbose rslib build

Install with Tessl CLI

npx tessl i tessl/npm-rslib--core

docs

build.md

cli.md

configuration.md

index.md

tile.json