App
App
is the application abstraction in the Esmx framework, providing a unified interface for managing application lifecycle, static assets, and server-side rendering.
entry.node.ts
1export default {
2 // Development environment configuration
3 async devApp(esmx) {
4 return import('@esmx/rspack').then((m) =>
5 m.createRspackHtmlApp(esmx, {
6 config(rc) {
7 // Custom Rspack configuration
8 }
9 })
10 );
11 }
12}
Type Definitions
App
1interface App {
2 middleware: Middleware;
3 render: (options?: RenderContextOptions) => Promise<RenderContext>;
4 build?: () => Promise<boolean>;
5 destroy?: () => Promise<boolean>;
6}
middleware
Static asset handling middleware.
Development environment:
- Processes static asset requests for source code
- Supports real-time compilation and hot module replacement
- Uses no-cache policy
Production environment:
- Handles built static assets
- Supports long-term caching for immutable files (.final.xxx)
- Optimized asset loading strategy
1server.use(esmx.middleware);
render
- Type:
(options?: RenderContextOptions) => Promise<RenderContext>
Server-side rendering function. Provides different implementations based on environment:
- Production (start): Loads and executes the built server entry file (entry.server) for rendering
- Development (dev): Loads and executes the source server entry file for rendering
1const rc = await esmx.render({
2 params: { url: '/page' }
3});
4res.end(rc.html);
build
- Type:
() => Promise<boolean>
Production build function. Used for asset bundling and optimization. Returns true on successful build, false on failure.
destroy
- Type:
() => Promise<boolean>
Resource cleanup function. Used for server shutdown, connection termination, etc. Returns true on successful cleanup, false on failure.