logo
Guide
API
Blog
简体中文
English
Guide
API
Blog
简体中文
English
logo

@esmx/core

Esmx
App
RenderContext
ModuleConfig
PackConfig
ManifestJson

App

@esmx/rspack
@esmx/rspack-vue

Last Updated: 11/20/2025, 2:11:30 AM

Previous Page@esmx/rspack

#@esmx/rspack-vue

The Rspack Vue package provides a set of APIs for creating and configuring Vue-based Rspack applications, supporting Vue component development, building, and Server-Side Rendering.

#Installation

Use package manager to install @esmx/rspack-vue as a development dependency:

npm
yarn
pnpm
bun
npm install @esmx/rspack-vue -D

#Type Exports

#BuildTarget

type BuildTarget = 'node' | 'client' | 'server'

Build target environment type that defines the target environment for application builds, used to configure specific optimizations and features in the build process:

  • node: Build code to run in Node.js environment
  • client: Build code to run in browser environment
  • server: Build code to run in server environment

#RspackAppConfigContext

interface RspackAppConfigContext {
  esmx: Esmx
  buildTarget: BuildTarget
  config: RspackOptions
  options: RspackAppOptions
}

Rspack application configuration context interface provides context information accessible in configuration hook functions:

  • esmx: Esmx framework instance
  • buildTarget: Current build target (client/server/node)
  • config: Rspack configuration object
  • options: Application configuration options

#RspackAppOptions

interface RspackAppOptions {
  css?: 'css' | 'js' | false
  loaders?: {
    styleLoader?: string
  }
  styleLoader?: Record<string, any>
  cssLoader?: Record<string, any>
  target?: {
    web?: string[]
    node?: string[]
  }
  definePlugin?: Record<string, any>
  config?: (context: RspackAppConfigContext) => void | Promise<void>
}

Rspack application configuration options interface:

  • css: CSS output method, optional 'css' (separate file) or 'js' (bundled into JS), defaults to automatic selection based on environment: production uses 'css' to optimize caching and parallel loading, development uses 'js' to support HMR
  • loaders: Custom loader configuration
  • styleLoader: style-loader configuration options
  • cssLoader: css-loader configuration options
  • target: Build target compatibility configuration
  • definePlugin: Global constant definitions
  • config: Configuration hook function

#RspackHtmlAppOptions

Inherits from RspackAppOptions, used to configure specific options for HTML applications.

#Function Exports

#createRspackApp

function createRspackApp(esmx: Esmx, options?: RspackAppOptions): Promise<App>

Creates a standard Rspack application instance.

Parameters:

  • esmx: Esmx framework instance
  • options: Rspack application configuration options

Returns:

  • Returns a Promise that resolves to the created application instance

#createRspackHtmlApp

function createRspackHtmlApp(esmx: Esmx, options?: RspackHtmlAppOptions): Promise<App>

Creates an HTML-type Rspack application instance.

Parameters:

  • esmx: Esmx framework instance
  • options: HTML application configuration options

Returns:

  • Returns a Promise that resolves to the created HTML application instance

#Constant Exports

#RSPACK_LOADER

const RSPACK_LOADER: Record<string, string> = {
  builtinSwcLoader: 'builtin:swc-loader',
  lightningcssLoader: 'builtin:lightningcss-loader',
  styleLoader: 'style-loader',
  cssLoader: 'css-loader',
  lessLoader: 'less-loader',
  styleResourcesLoader: 'style-resources-loader',
  workerRspackLoader: 'worker-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 files
  • lightningcssLoader: Rspack built-in lightningcss loader, a high-performance compiler for processing CSS files
  • styleLoader: Loader that injects CSS into the DOM
  • cssLoader: Loader that parses CSS files and handles CSS modularization
  • lessLoader: Loader that compiles Less files to CSS
  • styleResourcesLoader: Loader that automatically imports 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:

src/entry.node.ts
import { RSPACK_LOADER } from '@esmx/rspack';

export default {
  async devApp(esmx) {
    return import('@esmx/rspack').then((m) =>
      m.createRspackHtmlApp(esmx, {
        loaders: {
          // Use constants to reference loaders
          styleLoader: RSPACK_LOADER.styleLoader,
          cssLoader: RSPACK_LOADER.cssLoader,
          lightningcssLoader: RSPACK_LOADER.lightningcssLoader
        }
      })
    );
  }
};

Notes:

  • These loaders are already built into Rspack, requiring no additional installation
  • When customizing loader configuration, these constants can be used to replace default loader implementations
  • Some loaders (such as 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.