or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdcore-bundling.mdhmr.mdindex.mdloaders.mdmodule-federation.mdplugins.md
tile.json

tessl/npm-rspack--core

Fast Rust-based web bundler with webpack-compatible API

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@rspack/core@1.5.x

To install, run

npx @tessl/cli install tessl/npm-rspack--core@1.5.0

index.mddocs/

Rspack Core

Rspack is a high-performance JavaScript bundler built in Rust that offers strong compatibility with the webpack ecosystem. It serves as a drop-in replacement for webpack with significantly faster build speeds, featuring lightning-fast Hot Module Replacement (HMR), built-in incremental compilation, and first-class Module Federation support.

Package Information

  • Package Name: @rspack/core
  • Package Type: npm
  • Language: JavaScript/TypeScript with Rust bindings
  • Installation: npm install @rspack/core

Core Imports

import rspack from "@rspack/core";
import { Compiler, Compilation, Configuration } from "@rspack/core";

For CommonJS:

const rspack = require("@rspack/core");
const { Compiler, Compilation } = require("@rspack/core");

Basic Usage

import rspack from "@rspack/core";

// Simple build configuration
const config = {
  entry: "./src/index.js",
  output: {
    path: __dirname + "/dist",
    filename: "bundle.js",
  },
  mode: "production",
};

// Create and run compiler
const compiler = rspack(config);
compiler.run((err, stats) => {
  if (err) {
    console.error(err);
    return;
  }
  console.log(stats?.toString());
});

Architecture

Rspack is built around several key components:

  • Compiler: Main compilation controller that manages the build process and hooks system
  • Compilation: Individual build process instance with assets, modules, and chunks
  • Configuration System: Comprehensive options for build behavior, optimization, and plugins
  • Plugin System: Tapable-based hooks allowing deep customization of the build process
  • Module System: Module resolution, loading, and transformation pipeline
  • Hot Module Replacement: Development-time module swapping without full page reload
  • Module Federation: Micro-frontend architecture for sharing code between applications

Capabilities

Core Bundling

Main bundling functions and compiler creation for building JavaScript applications.

function rspack(options: Configuration): Compiler;
function rspack(options: Configuration[]): MultiCompiler;
function rspack(
  options: Configuration | Configuration[],
  callback: (err: Error | null, stats?: Stats | MultiStats) => void
): Compiler | MultiCompiler | null;

function createCompiler(options: Configuration): Compiler;
function createMultiCompiler(options: Configuration[]): MultiCompiler;

Core Bundling

Configuration

Comprehensive configuration options covering entry points, output, optimization, plugins, and development settings.

interface Configuration {
  entry?: Entry;
  output?: Output;
  mode?: Mode;
  target?: Target;
  module?: ModuleOptions;
  resolve?: ResolveOptions;
  plugins?: Plugin[];
  optimization?: Optimization;
  experiments?: Experiments;
  devServer?: DevServer;
  devtool?: DevTool;
  externals?: Externals;
  stats?: StatsValue;
}

type Mode = "development" | "production" | "none";
type Entry = string | string[] | EntryObject | EntryFunction;

Configuration

Plugin System

Built-in plugins for optimization, development, asset processing, and build customization.

interface RspackPluginInstance {
  apply(compiler: Compiler): void;
}

type RspackPluginFunction = (this: Compiler, compiler: Compiler) => void;
type Plugin = RspackPluginInstance | RspackPluginFunction | Falsy;

// Core plugins
class DefinePlugin extends RspackBuiltinPlugin {
  constructor(options: DefinePluginOptions);
}

class HotModuleReplacementPlugin extends RspackBuiltinPlugin {}
class ProvidePlugin extends RspackBuiltinPlugin {
  constructor(options: ProvidePluginOptions);
}

Plugin System

Hot Module Replacement

Development-time module replacement system for fast iteration without losing application state.

interface Hot {
  accept(
    modules?: string | string[],
    callback?: (outdatedDependencies: string[]) => void,
    errorHandler?: (err: Error, context: any) => void
  ): void;
  decline(module?: string | string[]): void;
  dispose(callback: (data: any) => void): void;
  status(): HotUpdateStatus;
  check(autoApply?: boolean): Promise<(string | number)[] | null>;
  apply(options?: ApplyOptions): Promise<(string | number)[] | null>;
  data: any;
}

type HotUpdateStatus = "idle" | "check" | "prepare" | "ready" | "dispose" | "apply" | "abort" | "fail";

Hot Module Replacement

Module Federation

Micro-frontend architecture enabling code sharing between independent applications at runtime.

class ModuleFederationPlugin extends RspackBuiltinPlugin {
  constructor(options: ModuleFederationPluginOptions);
}

interface ModuleFederationPluginOptions {
  name: string;
  filename?: string;
  exposes?: Exposes;
  remotes?: Remotes;  
  shared?: Shared;
  runtimePlugins?: string[];
  shareStrategy?: "version-first" | "loaded-first";
}

class ContainerPlugin extends RspackBuiltinPlugin {
  constructor(options: ContainerPluginOptions);
}

class ContainerReferencePlugin extends RspackBuiltinPlugin {
  constructor(options: ContainerReferencePluginOptions);
}

Module Federation

Loaders

Built-in loaders for transforming modules during the build process.

interface SwcLoaderOptions {
  jsc?: SwcLoaderJscConfig;
  module?: SwcLoaderModuleConfig;
  env?: SwcLoaderEnvConfig;
  isModule?: boolean;
  rspackExperiments?: {
    import?: any[];
    collectTypeScriptInfo?: boolean;
  };
}

interface LightningcssLoaderOptions {
  minify?: boolean;
  targets?: any;
  include?: number;
  exclude?: number;
  drafts?: any;
  nonStandard?: any;
  pseudoClasses?: any;
}

Loaders

Types

Core Types

class Compiler {
  options: Configuration;
  hooks: CompilerHooks;
  outputPath: string;
  name?: string;
  
  run(callback: (err: Error | null, stats?: Stats) => void): void;
  watch(
    options: WatchOptions,
    callback: (err: Error | null, stats?: Stats) => void
  ): Watching;
  close(callback: () => void): void;
}

class Compilation {
  assets: Record<string, Asset>;
  chunks: Set<Chunk>;
  modules: Set<Module>;
  moduleGraph: ModuleGraph;
  hooks: CompilationHooks;
}

class MultiCompiler {
  compilers: Compiler[];
  hooks: MultiCompilerHooks;
  
  run(callback: (err: Error | null, stats?: MultiStats) => void): void;
  watch(
    options: WatchOptions | WatchOptions[],
    callback: (err: Error | null, stats?: MultiStats) => void
  ): MultiWatching;
}

class Stats {
  compilation: Compilation;
  toString(options?: StatsOptions): string;
  toJson(options?: StatsOptions): StatsCompilation;
}

Asset and Module Types

interface Asset {
  source(): string | Buffer;
  size(): number;
  info?: AssetInfo;
}

interface AssetInfo {
  immutable?: boolean;
  minimized?: boolean;
  development?: boolean;
  hotModuleReplacement?: boolean;
  sourceFilename?: string;
  javascriptModule?: boolean;
}

class Module {
  type: string;
  context?: string;
  resource?: string;
  request?: string;
}

class Chunk {
  name?: string;
  id?: string | number;
  ids: (string | number)[];
  files: Set<string>;
  runtime: Set<string>;
}

Error Types

class RspackError extends Error {
  name: string;
  message: string;
  stack?: string;
}

class ValidationError extends Error {
  name: "ValidationError";
  errors: string[];
}

type RspackSeverity = "error" | "warning";