@esmx/rspack
The Rspack package provides a set of APIs for creating and configuring Rspack applications, supporting the building and development of standard applications and HTML applications.
Installation
Use package manager to install @esmx/rspack as a development dependency:
Type Exports
BuildTarget
Build target environment type that defines the application's build target environment:
node: Build code to run in Node.js environmentclient: Build code to run in browser environmentserver: Build code to run in server environment
RspackAppConfigContext
Rspack application configuration context interface provides context information accessible in configuration hook functions:
esmx: Esmx framework instancebuildTarget: Current build target (client/server/node)config: Rspack configuration objectoptions: Application configuration options
RspackAppChainContext
Rspack application chain configuration context interface for the chain hook function:
esmx: Esmx framework instancebuildTarget: Current build target (client/server/node)chain: rspack-chain configuration object for chained configurationoptions: Application configuration options
RspackAppOptions
Rspack application configuration options interface:
minimize: Whether to enable code minification,trueto enable,falseto disable,undefinedto automatically decide based on environment (enabled in production, disabled in development)config: Configuration hook function called before build starts for modifying Rspack compilation configurationchain: Chain configuration hook function using rspack-chain for flexible configuration modification
RspackHtmlAppOptions
Inherits from RspackAppOptions, used to configure specific options for HTML applications:
css: CSS output method, optional'css'(separate file) or'js'(bundled into JS), defaults to automatic selection based on environmentloaders: Custom loader configuration for replacing default loader implementationsstyleLoader: style-loader configuration optionscssLoader: css-loader configuration optionslessLoader: less-loader configuration optionsstyleResourcesLoader: Global style resources auto-injection configurationswcLoader: SWC loader configuration optionsdefinePlugin: Global constant definitionstarget: Build target compatibility configuration
Function Exports
createRspackApp
Create a standard Rspack application instance.
Parameters:
esmx— Esmx framework instanceoptions— Rspack application configuration options
Returns:
- Returns a
Promisethat resolves to the created application instance
createRspackHtmlApp
Create an HTML-type Rspack application instance.
Parameters:
esmx— Esmx framework instanceoptions— HTML application configuration options
Returns:
- Returns a
Promisethat resolves to the created HTML application instance
Constant Exports
RSPACK_LOADER
Rspack built-in loader identifier mapping object that provides commonly used loader name constants:
builtinSwcLoader: Rspack built-in SWC loader, for processing TypeScript/JavaScript fileslightningcssLoader: Rspack built-in LightningCSS loader, a high-performance compiler for processing CSS filesstyleLoader: Loader for injecting CSS into the DOMcssLoader: Loader for parsing CSS files and handling CSS modularizationlessLoader: Loader for compiling Less files to CSSstyleResourcesLoader: Loader for automatically importing global style resources (variables, mixins, etc.)workerRspackLoader: Loader for processing Web Worker files
Using these constants can reference built-in loaders in configuration, avoiding manual string input:
Notes:
- These loaders are already built into Rspack, no additional installation needed
- When customizing loader configuration, you can use these constants to replace default loader implementations
- Some loaders (like
builtinSwcLoader) have specific configuration options, please refer to the corresponding configuration documentation
Module Exports
rspack
Re-exports all contents from @rspack/core package, providing complete Rspack core functionality.