This directory contains all map-related scripts that will be executed in the browser by WorkAdventure.
main.ts: Main map script (referenced in.tmjfiles)
All map scripts MUST be placed in this src/ directory to work correctly. Scripts placed elsewhere will NOT be compiled and will cause errors.
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
- 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
// 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"
}
]
}- ❌ 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
See the main README.md for more information about the project structure.