Fast Rust-based web bundler with webpack-compatible API
npx @tessl/cli install tessl/npm-rspack--core@1.5.0Rspack 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.
npm install @rspack/coreimport rspack from "@rspack/core";
import { Compiler, Compilation, Configuration } from "@rspack/core";For CommonJS:
const rspack = require("@rspack/core");
const { Compiler, Compilation } = require("@rspack/core");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());
});Rspack is built around several key components:
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;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;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);
}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";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);
}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;
}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;
}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>;
}class RspackError extends Error {
name: string;
message: string;
stack?: string;
}
class ValidationError extends Error {
name: "ValidationError";
errors: string[];
}
type RspackSeverity = "error" | "warning";