Fast Rust-based web bundler with webpack-compatible API
—
Comprehensive configuration options covering entry points, output settings, optimization, plugins, and development features for customizing the build process.
Primary configuration object for customizing build behavior.
interface Configuration {
/** Entry points for the application */
entry?: Entry;
/** Output configuration */
output?: Output;
/** Build mode affecting default optimizations */
mode?: Mode;
/** Target environment for the build */
target?: Target;
/** Module processing rules and options */
module?: ModuleOptions;
/** Module resolution configuration */
resolve?: ResolveOptions;
/** Array of plugins to apply */
plugins?: Plugin[];
/** Build optimization settings */
optimization?: Optimization;
/** Experimental features */
experiments?: Experiments;
/** Development server configuration */
devServer?: DevServer;
/** Source map generation */
devtool?: DevTool;
/** External dependencies configuration */
externals?: Externals;
/** Build statistics output */
stats?: StatsValue;
/** Configuration name for multi-compiler */
name?: string;
/** Dependencies on other configurations */
dependencies?: string[];
/** Watch mode options */
watch?: boolean;
/** Watch configuration */
watchOptions?: WatchOptions;
}Entry points define where the bundler starts building the dependency graph.
type Entry = string | string[] | EntryObject | EntryFunction;
/** Simple string entry */
type EntryString = string;
/** Array of entry files */
type EntryArray = string[];
/** Object with named entry points */
interface EntryObject {
[name: string]: EntryDescription | string | string[];
}
/** Detailed entry configuration */
interface EntryDescription {
/** Entry file(s) */
import: string | string[];
/** Dependencies that must be loaded before this entry */
dependOn?: string | string[];
/** Runtime chunk name */
runtime?: string | false;
/** Filename template for this entry */
filename?: string;
/** Chunk loading method */
chunkLoading?: ChunkLoading;
/** Async chunks method */
asyncChunks?: boolean;
/** Public path for this entry */
publicPath?: string;
/** Base URI for this entry */
baseUri?: string;
}
/** Function-based entry for dynamic entries */
type EntryFunction = () => Entry | Promise<Entry>;
/** Chunk loading methods */
type ChunkLoading = "jsonp" | "import-scripts" | "require" | "async-node" | "import" | false;Usage Examples:
// String entry
const config = {
entry: "./src/index.js"
};
// Array entry
const config = {
entry: ["./src/polyfills.js", "./src/index.js"]
};
// Object entry with multiple bundles
const config = {
entry: {
app: "./src/app.js",
admin: "./src/admin.js",
vendor: ["react", "react-dom"]
}
};
// Detailed entry configuration
const config = {
entry: {
main: {
import: "./src/index.js",
dependOn: "vendor",
runtime: "main-runtime"
},
vendor: {
import: ["react", "react-dom"],
runtime: "vendor-runtime"
}
}
};
// Dynamic entry
const config = {
entry: async () => {
const entries = await getEntryPoints();
return entries;
}
};Controls how bundles are emitted and where they are placed.
interface Output {
/** Output directory path */
path?: string;
/** Bundle filename template */
filename?: string;
/** Public URL path for assets */
publicPath?: string;
/** Chunk filename template */
chunkFilename?: string;
/** Asset filename template */
assetModuleFilename?: string;
/** Library configuration for exporting */
library?: LibraryOptions;
/** Environment features to assume */
environment?: Environment;
/** Clean output directory before build */
clean?: boolean;
/** Compare outputs and only emit changed files */
compareBeforeEmit?: boolean;
/** Source map filename template */
sourceMapFilename?: string;
/** Hot update chunk filename */
hotUpdateChunkFilename?: string;
/** Hot update main filename */
hotUpdateMainFilename?: string;
/** Unique name for this build */
uniqueName?: string;
/** Chunk loading method */
chunkLoading?: ChunkLoading;
/** WebAssembly loading method */
wasmLoading?: WasmLoading;
/** Worker chunk loading */
workerChunkLoading?: ChunkLoading;
}
interface LibraryOptions {
/** Library name */
name?: string | string[] | LibraryCustomUmdObject;
/** Export format */
type?: LibraryType;
/** UMD named define */
umdNamedDefine?: boolean;
/** Auxiliary comment */
auxiliaryComment?: string | LibraryAuxiliaryComment;
/** Export property */
export?: string | string[];
}
interface Environment {
/** Arrow functions support */
arrowFunction?: boolean;
/** BigInt support */
bigIntLiteral?: boolean;
/** const/let support */
const?: boolean;
/** Destructuring support */
destructuring?: boolean;
/** Dynamic import support */
dynamicImport?: boolean;
/** for...of support */
forOf?: boolean;
/** Module system support */
module?: boolean;
/** Optional chaining support */
optionalChaining?: boolean;
/** Template literals support */
templateLiteral?: boolean;
}
type LibraryType = "var" | "module" | "assign" | "assign-properties" | "this" | "window" |
"self" | "global" | "commonjs" | "commonjs2" | "commonjs-module" | "amd" | "amd-require" |
"umd" | "umd2" | "jsonp" | "system";
type WasmLoading = "fetch-streaming" | "fetch" | "async-node" | false;Controls how different module types are processed and transformed.
interface ModuleOptions {
/** Array of rules for processing modules */
rules?: RuleSetRule[];
/** Parser options by module type */
parser?: { [moduleType: string]: any };
/** Generator options by module type */
generator?: { [moduleType: string]: any };
/** Prevent parsing for certain modules */
noParse?: RegExp | RegExp[] | ((request: string) => boolean) | string | string[];
/** Unsupported features that should cause errors */
unsafeCache?: boolean | ((module: any) => boolean);
/** Default type for modules */
defaultRules?: RuleSetRule[];
}
interface RuleSetRule {
/** Match condition for resource */
test?: RuleSetCondition;
/** Include condition */
include?: RuleSetCondition;
/** Exclude condition */
exclude?: RuleSetCondition;
/** Resource condition */
resource?: RuleSetCondition;
/** Resource query condition */
resourceQuery?: RuleSetCondition;
/** Issuer condition */
issuer?: RuleSetCondition;
/** Module type */
type?: string;
/** Loaders to apply */
use?: RuleSetUseItem | RuleSetUseItem[];
/** Loader with options (shorthand) */
loader?: string;
/** Options for the loader */
options?: any;
/** Parser options */
parser?: any;
/** Generator options */
generator?: any;
/** Resolve options */
resolve?: ResolveOptions;
/** Side effects flag */
sideEffects?: boolean;
/** Enforcement order */
enforce?: "pre" | "post";
/** Nested rules */
oneOf?: RuleSetRule[];
/** Multiple rule sets (all must match) */
rules?: RuleSetRule[];
}
type RuleSetCondition = string | RegExp | ((value: string) => boolean) |
RuleSetLogicalConditions | RuleSetCondition[];
interface RuleSetLogicalConditions {
and?: RuleSetCondition[];
or?: RuleSetCondition[];
not?: RuleSetCondition;
}
type RuleSetUseItem = string | RuleSetLoader | ((context: any) => RuleSetLoader);
interface RuleSetLoader {
loader: string;
options?: any;
}Controls how modules are resolved and located.
interface ResolveOptions {
/** Path aliases */
alias?: { [key: string]: string | false | string[] };
/** Alias for field names */
aliasFields?: string[] | string[][];
/** Cache resolution results */
cache?: boolean;
/** Condition names for exports field */
conditionNames?: string[];
/** Description files to read */
descriptionFiles?: string[];
/** Enforce extension presence */
enforceExtension?: boolean;
/** File extensions to try */
extensions?: string[];
/** Fallback locations */
fallback?: { [key: string]: string | false | string[] };
/** Package.json fields to check for entry points */
mainFields?: string[];
/** Main files to look for */
mainFiles?: string[];
/** Directories to search for modules */
modules?: string[];
/** Plugins for resolver */
plugins?: any[];
/** Prefer relative paths */
preferRelative?: boolean;
/** Symlink resolution */
symlinks?: boolean;
/** Unsafe cache */
unsafeCache?: boolean | RegExp | ((request: string) => boolean);
/** Use sync file system calls */
useSyncFileSystemCalls?: boolean;
}Build optimization settings including minification, code splitting, and tree shaking.
interface Optimization {
/** Enable/disable minification */
minimize?: boolean;
/** Custom minimizers */
minimizer?: Plugin[];
/** Remove available modules optimization */
removeAvailableModules?: boolean;
/** Remove empty chunks */
removeEmptyChunks?: boolean;
/** Merge duplicate chunks */
mergeDuplicateChunks?: boolean;
/** Flag dependency usage */
flagIncludedChunks?: boolean;
/** Module concatenation optimization */
concatenateModules?: boolean;
/** Side effects optimization */
sideEffects?: boolean | "flag";
/** Provided exports optimization */
providedExports?: boolean;
/** Used exports optimization */
usedExports?: boolean | "global";
/** Inner graph analysis */
innerGraph?: boolean;
/** Mangle exports */
mangleExports?: boolean | "deterministic" | "size";
/** Mangle webpack runtime */
mangleWasmImports?: boolean;
/** Node.js modules polyfills */
nodeEnv?: string | false;
/** Code splitting configuration */
splitChunks?: OptimizationSplitChunksOptions;
/** Runtime chunk extraction */
runtimeChunk?: OptimizationRuntimeChunk;
/** Emit on errors */
emitOnErrors?: boolean;
/** Real content hash */
realContentHash?: boolean;
}
interface OptimizationSplitChunksOptions {
/** Chunks to split */
chunks?: "all" | "async" | "initial" | ((chunk: any) => boolean);
/** Minimum size for chunk creation */
minSize?: number;
/** Minimum size reduction for chunk creation */
minSizeReduction?: number;
/** Minimum remaining size after splitting */
minRemainingSize?: number;
/** Maximum size hint for chunks */
maxSize?: number;
/** Maximum async size hint */
maxAsyncSize?: number;
/** Maximum initial size hint */
maxInitialSize?: number;
/** Minimum chunks sharing a module */
minChunks?: number;
/** Maximum number of async requests */
maxAsyncRequests?: number;
/** Maximum number of initial requests */
maxInitialRequests?: number;
/** Cache groups configuration */
cacheGroups?: { [key: string]: OptimizationSplitChunksCacheGroup };
/** Default name for chunks */
name?: boolean | string | ((module: any, chunks: any[], key: string) => string);
/** Filename template */
filename?: string;
/** Automatically generate names */
automaticNameDelimiter?: string;
/** Hide path info */
hidePathInfo?: boolean;
/** Enforce size limits */
enforceSizeThreshold?: number;
}
interface OptimizationSplitChunksCacheGroup {
/** Test condition */
test?: RegExp | string | ((module: any) => boolean);
/** Chunk selection */
chunks?: "all" | "async" | "initial" | ((chunk: any) => boolean);
/** Enforce this cache group */
enforce?: boolean;
/** Priority for this cache group */
priority?: number;
/** Reuse existing chunks */
reuseExistingChunk?: boolean;
/** Filename for chunks */
filename?: string;
/** Name for chunks */
name?: boolean | string | ((module: any, chunks: any[], key: string) => string);
/** Minimum size */
minSize?: number;
/** Maximum size */
maxSize?: number;
/** Minimum chunks */
minChunks?: number;
}
type OptimizationRuntimeChunk = boolean | "single" | "multiple" |
{ name?: string | ((entrypoint: any) => string) };/** Build mode affecting default configurations */
type Mode = "development" | "production" | "none";
/** Target environment for the build */
type Target = string | string[] | false;Usage Examples:
// Basic configuration
const config = {
entry: "./src/index.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].[contenthash].js",
publicPath: "/assets/",
clean: true
},
mode: "production",
target: ["web", "es2015"],
module: {
rules: [
{
test: /\.tsx?$/,
use: "swc-loader",
exclude: /node_modules/
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
}
]
},
resolve: {
extensions: [".js", ".ts", ".tsx"],
alias: {
"@": path.resolve(__dirname, "src")
}
},
optimization: {
minimize: true,
splitChunks: {
chunks: "all",
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: "vendors",
chunks: "all"
}
}
},
runtimeChunk: "single"
}
};Install with Tessl CLI
npx tessl i tessl/npm-rspack--core