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 PageEsmx
Next PageRenderContext

#App

App is the application abstraction for the Esmx framework, providing a unified interface to manage application lifecycle, static resources, and Server-Side Rendering.

entry.node.ts
export default {
  async devApp(esmx) {
    return import('@esmx/rspack').then((m) =>
      m.createRspackHtmlApp(esmx, {
        config(rc) {
        }
      })
    );
  }
}

#Type Definitions

#App

interface App {
  middleware: Middleware;
  render: (options?: RenderContextOptions) => Promise<RenderContext>;
  build?: () => Promise<boolean>;
  destroy?: () => Promise<boolean>;
}

#middleware

  • Type: Middleware

Static resource handling middleware.

Development Environment:

  • Handles static resource requests from source code
  • Supports real-time compilation and hot reloading
  • Uses no-cache caching strategy

Production Environment:

  • Handles static resources after building
  • Supports long-term caching for immutable files (.final.xxx)
  • Optimized resource loading strategy
server.use(esmx.middleware);

#render

  • Type: (options?: RenderContextOptions) => Promise<RenderContext>

Server-Side Rendering function. Provides different implementations based on the runtime environment:

  • Production environment (start): Loads the built server entry file (entry.server) to execute rendering
  • Development environment (dev): Loads the server entry file from source code to execute rendering
const rc = await esmx.render({
  params: { url: '/page' }
});
res.end(rc.html);

#build

  • Type: () => Promise<boolean>

Production environment build function. Used for resource bundling and optimization. Returns true upon successful build, false upon failure.

#destroy

  • Type: () => Promise<boolean>

Resource cleanup function. Used to close the server, disconnect connections, etc. Returns true upon successful cleanup, false upon failure.