C# to JavaScript compiler

# Global Configuration

The h5.json file is the global configuration file for an h5 project. It is typically located in the root directory of your project alongside the .csproj file. This file controls various aspects of the compilation process, output generation, and runtime behavior.

The compiler uses this file to determine how to translate your C# code into JavaScript. If h5.json is missing, the compiler will use default settings.

# Basic Structure

A minimal h5.json file might look like this:

{
  "output": "h5/"
}

# Configuration Options

Below is a list of available configuration options in h5.json.

# output

Type: string

Specifies the output directory for the generated JavaScript files. The path can be absolute or relative to the project root.

{
  "output": "bin/Debug/netstandard2.1/h5/"
}

You can also use MSBuild properties in the path, such as $(OutDir).

# fileName

Type: string

The name of the main JavaScript file to be generated. If omitted, it defaults to the assembly name (e.g., MyProject.js).

{
  "fileName": "app.js"
}

# sourceMap

Type: object

Configures the generation of source maps, which allow you to debug your C# code directly in the browser.

{
  "sourceMap": {
    "enabled": true,
    "debug": true
  }
}
  • enabled: Set to true to generate .js.map files.

# html

Type: object

Configures the automatic generation of an index.html file to run your application.

{
  "html": {
    "disabled": false,
    "title": "My h5 App"
  }
}
  • disabled: Set to true to disable HTML generation.
  • title: Sets the <title> of the generated HTML page.

# reflection

Type: object

Controls the generation of reflection metadata. By default, h5 generates metadata to support C# reflection features.

{
  "reflection": {
    "disabled": false,
    "target": "File"
  }
}
  • disabled: Set to true to disable reflection metadata generation.
  • target: File (default) generates a separate .meta.js file. Inline includes metadata in the main JS file.

# resources

Type: array

Manages embedded resources and their extraction.

{
  "resources": [
    {
      "name": "style.css",
      "files": ["css/style.css"]
    }
  ]
}

# beforeBuild / afterBuild

Type: string

Commands to execute before or after the build process.

{
  "beforeBuild": "npm install",
  "afterBuild": "echo Build Complete"
}

# cleanOutputFolderBeforeBuild

Type: boolean

If true, cleans the output folder before generating new files.

{
  "cleanOutputFolderBeforeBuild": true
}

# locales

Type: string

Specifies which locales to include in the build.

{
  "locales": "en-US;fr-FR"
}
  • all: Include all available locales.
  • en-US: Include specific locale.

# module

Type: string

Defines the module system to use. See Output Types for more details.

{
  "module": "CommonJS"
}
  • Supported values: AMD, CommonJS, ES6, UMD, None (default).

# rules

Type: object

Configures compiler rules to fine-tune the generated JavaScript.

{
  "rules": {
    "anonymousType": "Plain",
    "autoProperty": "Plain"
  }
}
  • anonymousType: Managed (default) or Plain (simple JS object).
  • autoProperty: Managed (default) or Plain (simple field).

# pluginsPath

Type: string

Path to a directory containing compiler plugins.

{
  "pluginsPath": "plugins/"
}

# generateTypeScript

Type: boolean

If true, generates TypeScript declaration files (.d.ts) alongside the JavaScript files.

{
  "generateTypeScript": true
}

# generateDocumentation

Type: string

Controls the generation of JSDoc comments.

  • None: No documentation.
  • Basic: Basic documentation.
  • Full: Full documentation including parameter types.
{
  "generateDocumentation": "Full"
}

# Custom Configuration Files

You can create environment-specific configuration files, such as h5.Debug.json or h5.Release.json. The compiler will automatically load the configuration matching the current build configuration (e.g., dotnet build -c Release).