Standard Specifications

Esmx is a modern SSR framework that adopts standardized project structures and path resolution mechanisms to ensure consistency and maintainability across development and production environments.

Project Structure Standards

Standard Directory Structure

root
│─ dist                  # Build output directory
│  ├─ package.json       # Compiled package configuration
│  ├─ server             # Server-side build output
│  │  └─ manifest.json   # Build manifest output for generating importmap
│  ├─ node               # Node server program build output
│  ├─ client             # Client-side build output
│  │  ├─ versions        # Version storage directory
│  │  │  └─ latest.tgz   # Archived dist directory for package distribution
│  │  └─ manifest.json   # Build manifest output for generating importmap
│  └─ src                # Files generated by tsc
├─ src
│  ├─ entry.server.ts    # Server application entry
│  ├─ entry.client.ts    # Client application entry
│  └─ entry.node.ts      # Node server application entry
├─ tsconfig.json         # TypeScript configuration
└─ package.json          # Package configuration
Extended Knowledge
  • esmx.name is derived from the name field in package.json
  • dist/package.json is copied from the root package.json
  • The dist directory will only be archived when packs.enable is set to true

Entry File Specifications

entry.client.ts

The client entry file is responsible for:

  • Application Initialization: Configuring basic client application settings
  • Routing Management: Handling client-side routing and navigation
  • State Management: Implementing client-side state storage and updates
  • Interaction Handling: Managing user events and UI interactions

entry.server.ts

The server entry file is responsible for:

  • Server-Side Rendering: Executing SSR rendering processes
  • HTML Generation: Building initial page structures
  • Data Prefetching: Handling server-side data fetching
  • State Injection: Transferring server state to the client
  • SEO Optimization: Ensuring search engine optimization

entry.node.ts

The Node.js server entry file is responsible for:

  • Server Configuration: Setting HTTP server parameters
  • Routing Handling: Managing server-side routing rules
  • Middleware Integration: Configuring server middleware
  • Environment Management: Handling environment variables and configurations
  • Request/Response: Processing HTTP requests and responses

Configuration File Standards

package.json

package.json
{
    "name": "your-app-name",
    "type": "module",
    "scripts": {
        "dev": "esmx dev",
        "build": "npm run build:dts && npm run build:ssr",
        "build:ssr": "esmx build",
        "build:dts": "tsc --declaration --emitDeclarationOnly --outDir dist/src",
        "preview": "esmx preview",
        "start": "esmx start"
    }
}

tsconfig.json

tsconfig.json
{
    "compilerOptions": {
        "isolatedModules": true,
        "allowJs": false,
        "experimentalDecorators": true,
        "resolveJsonModule": true,
        "types": [
            "@types/node"
        ],
        "target": "ESNext",
        "module": "ESNext",
        "importHelpers": false,
        "declaration": true,
        "sourceMap": true,
        "strict": true,
        "noImplicitAny": false,
        "noImplicitReturns": false,
        "noFallthroughCasesInSwitch": true,
        "noUnusedLocals": false,
        "noUnusedParameters": false,
        "moduleResolution": "node",
        "esModuleInterop": true,
        "skipLibCheck": true,
        "allowSyntheticDefaultImports": true,
        "forceConsistentCasingInFileNames": true,
        "noEmit": true
    },
    "include": [
        "src",
        "**.ts"
    ],
    "exclude": [
        "dist"
    ]
}