Map Scripts (src/)

February 4, 2026 ยท View on GitHub

This directory contains all map-related scripts that will be executed in the browser by WorkAdventure.

๐Ÿ“ Structure

  • main.ts: Main map script (referenced in .tmj files)

โš ๏ธ CRITICAL: Scripts MUST be in src/

All map scripts MUST be placed in this src/ directory to work correctly. Scripts placed elsewhere will NOT be compiled and will cause errors.

Why src/?

Scripts in this directory are:

  • โœ… Automatically transformed from TypeScript to JavaScript
  • โœ… Bundled with npm dependencies (like @workadventure/scripting-api-extra)
  • โœ… Served with correct MIME types (application/javascript)
  • โœ… Referenced in .tmj files using paths like src/main.ts

How to Use

  1. Create your TypeScript script in src/ (e.g., src/my-script.ts)
  2. Reference it in your .tmj file's script property: "src/my-script.ts"
  3. The script will be automatically compiled and bundled when accessed

Example

// src/main.ts
import { bootstrapExtra } from "@workadventure/scripting-api-extra";

WA.onInit().then(() => {
    console.info('Map script loaded!');
    // Your map logic here
});

Then in your .tmj file:

{
  "properties": [
    {
      "name": "script",
      "type": "string",
      "value": "src/main.ts"
    }
  ]
}

๐Ÿšซ What NOT to Do

  • โŒ Don't place map scripts in app/ (reserved for the server entry point)
  • โŒ Don't place map scripts in public/ (static files)
  • โŒ Don't place map scripts in the root directory
  • โŒ Don't reference scripts outside src/ in your .tmj files

๐Ÿ“š Learn More

See the main README.md for more information about the project structure.