Esmx is a high-performance web application framework based on Rspack, providing comprehensive application lifecycle management, static asset handling, and server-side rendering capabilities.
Application runtime environment types:
client
: Runs in browser environment, supports DOM operations and browser APIsserver
: Runs in Node.js environment, supports filesystem and server-side functionalitiesES Module import map type.
Module specifier mapping type, used to define module import path mappings.
Scope mapping type, used to define module import mappings within specific scopes.
Command type enumeration:
dev
: Development environment command, starts development server with hot reloadbuild
: Build command, generates production build artifactspreview
: Preview command, launches local preview serverstart
: Start command, runs production serverDefines core configuration options for the Esmx framework.
string
process.cwd()
Project root directory path. Can be absolute or relative path (resolved relative to current working directory).
boolean
process.env.NODE_ENV === 'production'
Environment flag:
true
: Production environmentfalse
: Development environmentstring | false
'[[[___GEZ_DYNAMIC_BASE___]]]'
Base path placeholder configuration. Used for runtime dynamic replacement of asset base paths. Set to false
to disable this feature.
ModuleConfig
Module configuration options. Used to configure project module resolution rules, including module aliases, external dependencies, etc.
PackConfig
Packaging configuration options. Used to package build artifacts into standard npm .tgz format packages.
(esmx: Esmx) => Promise<App>
Development environment application creation function. Only used in development environment to create application instances for development server.
(esmx: Esmx) => Promise<void>
Server startup configuration function. Used to configure and start HTTP server, available in both development and production environments.
(esmx: Esmx) => Promise<void>
Post-build processing function. Executed after project build completes, can be used for:
string
true
Current module name, derived from module configuration.
string
true
Valid JavaScript variable name generated from module name.
string
true
Absolute path to project root directory. If configured root
is relative path, resolved relative to current working directory.
boolean
true
Determines whether current environment is production. Prioritizes isProd
from configuration, otherwise uses process.env.NODE_ENV
.
string
true
NotReadyError
- When framework is not initializedGets module base path with leading and trailing slashes. Returns format /${name}/
, where name comes from module configuration.
string
true
Gets base path placeholder for runtime dynamic replacement. Can be disabled via configuration.
Middleware
true
Gets static asset handling middleware. Provides different implementations based on environment:
(options?: RenderContextOptions) => Promise<RenderContext>
true
Gets server-side rendering function. Provides different implementations based on environment:
typeof COMMAND
true
Gets command enumeration type definition.
ParsedModuleConfig
true
NotReadyError
- When framework is not initializedGets complete configuration information for current module, including module resolution rules, alias configurations, etc.
ParsedPackConfig
true
NotReadyError
- When framework is not initializedGets packaging-related configuration for current module, including output paths, package.json processing, etc.
options?: EsmxOptions
- Framework configuration optionsEsmx
Creates Esmx framework instance.
command: COMMAND
Promise<boolean>
Error
: When initializing repeatedlyNotReadyError
: When accessing uninitialized instanceInitializes Esmx framework instance. Executes core initialization processes:
NotReadyError
when accessing uninitialized instance
:::Promise<boolean>
Destroys Esmx framework instance, performs resource cleanup and connection closing. Mainly used for:
Promise<boolean>
Executes application build process, including:
::: warning Note
Throws NotReadyError
when called on uninitialized framework instance
Promise<void>
NotReadyError
- When framework is not initializedStarts HTTP server and configures server instance. Called during following lifecycles:
Promise<boolean>
Executes post-build processing logic, used for:
Resolves project path, converts relative paths to absolute paths.
Parameters:
projectPath: ProjectPath
- Project path type...args: string[]
- Path segmentsReturns: string
- Resolved absolute path
Example:
Synchronously writes file content.
Parameters:
filepath
: string
- Absolute file pathdata
: any
- Data to write, can be string, Buffer or objectReturns: boolean
- Whether write succeeded
Example:
Synchronously reads and parses JSON file.
Parameters:
filename
: string
- Absolute path to JSON fileReturns: any
- Parsed JSON object
Exceptions: Throws when file doesn't exist or JSON is malformed
Example:
Asynchronously reads and parses JSON file.
Parameters:
filename
: string
- Absolute path to JSON fileReturns: Promise<any>
- Parsed JSON object
Exceptions: Throws when file doesn't exist or JSON is malformed
Example:
Gets build manifest list.
Parameters:
target
: BuildSsrTarget
- Target environment type
'client'
: Client environment'server'
: Server environmentReturns: Promise<readonly ManifestJson[]>
- Read-only build manifest list
Exceptions: Throws NotReadyError
when framework instance is not initialized
This method retrieves build manifest list for specified target environment, with following features:
Cache Management
Environment Adaptation
Module Mapping
Gets import map object.
Parameters:
target
: BuildSsrTarget
- Target environment type
'client'
: Generates browser environment import map'server'
: Generates server environment import mapReturns: Promise<Readonly<ImportMap>>
- Read-only import map object
Exceptions: Throws NotReadyError
when framework instance is not initialized
This method generates ES Module import maps (Import Map), with following characteristics:
Module Resolution
Cache Optimization
Path Handling
Gets client import map information.
Parameters:
mode
: ImportmapMode
- Import map mode
'inline'
: Inline mode, returns HTML script tag'js'
: JS file mode, returns information with file pathReturns:
Exceptions: Throws NotReadyError
when framework instance is not initialized
This method generates client environment import map code, supporting two modes:
Inline Mode (inline)
JS File Mode (js)
Core features:
Automatically handles dynamic base paths
Supports runtime module path replacement
Optimizes caching strategy
Ensures module loading order
Example:
Gets module's static import path list.
Parameters:
target
: BuildSsrTarget
- Build target
'client'
: Client environment'server'
: Server environmentspecifier
: string
- Module specifierReturns: Promise<readonly string[] | null>
- Returns static import path list, returns null if not found
Exceptions: Throws NotReadyError
when framework instance is not initialized
Example: