About
@nanoforge-dev/ecs is NanoForge’s built-in entity-component-system library, backed by a WebAssembly registry (compiled from C++). It ships two subpath entry points — @nanoforge-dev/ecs/client and @nanoforge-dev/ecs/server — each loading its own WASM build (browser-targeted vs Node-targeted) behind the same EcsLibrary API, so a client bundle never pulls in the server build or vice versa. The root entry point, @nanoforge-dev/ecs, only exposes the shared types (Registry, Component, System, Entity, SparseArray, Context, EcsContextApi) and pulls in no WASM binary, so it’s safe to import from code that targets both client and server.
Installation
Node.js 26 or newer is required.Example usage
RegisterEcsLibrary from the entry point matching your app:
Registry, Component, and System are available from the root entry point, regardless of which platform you’re targeting:
Context.ecs.registry gives every other library access to the entity/component registry:
@nanoforge-dev/editor’s EditorLibrary, EcsLibrary also listens for a "hot-reload" command from the editor and applies incoming components via registry.addComponent — useful for live-editing entity state from an external editor host.
Scenes
@nanoforge-dev/ecs/scene has EcsScene, a scene of @nanoforge-dev/scene whose entities and systems go away when it is unloaded. Write its setup like an app’s main:
setup gets is the app’s, tracked: at unload, the systems added through it are removed (by function) and the entities spawned through it are killed, after calling the destroy() of their components that have one. teardown(registry, ctx) runs first, if the scene has one.
Links
Contributing
Before creating an issue, please ensure that it hasn’t already been reported/suggested, and double-check the documentation.See the contribution guide if you’d like to submit a PR.
