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.tmjfiles)
โ ๏ธ 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
.tmjfiles using paths likesrc/main.ts
How to Use
- Create your TypeScript script in
src/(e.g.,src/my-script.ts) - Reference it in your
.tmjfile'sscriptproperty:"src/my-script.ts" - 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.tmjfiles
๐ Learn More
See the main README.md for more information about the project structure.