ModuleConfig

ModuleConfig provides module configuration capabilities for the Esmx framework, used to define module import/export rules, alias configurations, and external dependencies.

Type Definitions

PathType

  • Type Definition:
1enum PathType {
2  npm = 'npm:', 
3  root = 'root:'
4}

Module path type enumeration:

  • npm: Represents dependencies in node_modules
  • root: Represents files under the project root directory

ModuleConfig

  • Type Definition:
1interface ModuleConfig {
2  exports?: string[]
3  links?: Record<string, string>
4  imports?: Record<string, string>
5}

Module configuration interface used to define service exports, imports, and external dependency configurations.

exports

Export configuration list that exposes specific code units (such as components, utility functions, etc.) from the service in ESM format.

Supports two types:

  • root:*: Exports source files, e.g., root:src/components/button.vue
  • npm:*: Exports third-party dependencies, e.g., npm:vue

Each export item contains the following properties:

  • name: Original export path, e.g., npm:vue or root:src/components
  • type: Path type (npm or root)
  • importName: Import name in the format: ${serviceName}/${type}/${path}
  • exportName: Export path relative to the service root directory
  • exportPath: Actual file path
  • externalName: External dependency name used as an identifier when other services import this module

Service dependency configuration mapping used to configure other services (local or remote) that the current service depends on and their local paths. Each configuration item's key is the service name, and the value is the local path of that service.

Configuration varies by installation method:

  • Source installation (Workspace, Git): Needs to point to the dist directory as it requires built files
  • Package installation (Link, static server, private registry, File): Directly points to the package directory as it already contains built files

imports

External dependency mapping that configures external dependencies to be used, typically dependencies from remote modules.

Each dependency item contains the following properties:

  • match: Regular expression used to match import statements
  • import: Actual module path

Example:

entry.node.ts
1import type { EsmxOptions } from '@esmx/core';
2
3export default {
4  modules: {
5    // Export configuration
6    exports: [
7      'root:src/components/button.vue',  // Export source file
8      'root:src/utils/format.ts',
9      'npm:vue',  // Export third-party dependency
10      'npm:vue-router'
11    ],
12
13    // Import configuration
14    links: {
15      // Source installation: Needs to point to dist directory
16      'ssr-remote': './node_modules/ssr-remote/dist',
17      // Package installation: Directly points to package directory
18      'other-remote': './node_modules/other-remote'
19    },
20
21    // External dependency configuration
22    imports: {
23      'vue': 'ssr-remote/npm/vue',
24      'vue-router': 'ssr-remote/npm/vue-router'
25    }
26  }
27} satisfies EsmxOptions;

ParsedModuleConfig

  • Type Definition:
1interface ParsedModuleConfig {
2  name: string
3  root: string
4  exports: {
5    name: string
6    type: PathType
7    importName: string
8    exportName: string
9    exportPath: string
10    externalName: string
11  }[]
12  links: Array<{
13    /**
14     * Package name
15     */
16    name: string
17    /**
18     * Package root directory
19     */
20    root: string
21  }>
22  imports: Record<string, { match: RegExp; import?: string }>
23}

Parsed module configuration that converts the original module configuration into a standardized internal format:

name

Current service name

  • Used to identify modules and generate import paths

root

Current service root directory path

  • Used to resolve relative paths and store build artifacts

exports

Export configuration list

  • name: Original export path, e.g., 'npm:vue' or 'root:src/components'
  • type: Path type (npm or root)
  • importName: Import name in the format: '${serviceName}/${type}/${path}'
  • exportName: Export path relative to the service root directory
  • exportPath: Actual file path
  • externalName: External dependency name used as an identifier when other services import this module

Import configuration list

  • name: Package name
  • root: Package root directory

imports

External dependency mapping

  • Maps module import paths to actual module locations
  • match: Regular expression used to match import statements
  • import: Actual module path