Packages & Imports
Every directory in the repo is a standalone npm package (except packages/tests, which exists only for testing). Understanding how the packages are layered avoids questions like "why can't my node be created" or "why does the bundle contain two copies of the engine".
Package overview
| Package | Directory | Depends on core | Contents |
|---|---|---|---|
@gausszhou/litegraph-core | packages/core | — | Engine core: LiteGraph, LGraph, LGraphNode, LGraphCanvas, LLink, LGraphGroup, Subgraph, GraphInput, GraphOutput |
@gausszhou/litegraph | packages/litegraph | Yes | Aggregate package: installs every node pack and re-exports all core APIs |
@gausszhou/litegraph-nodes-basic | packages/nodes-basic | Yes | Constants, watch, reroute, time, comparison, array access |
@gausszhou/litegraph-nodes-math | packages/nodes-math | Yes | Math operations, rounding, random, approximate equality |
@gausszhou/litegraph-nodes-logic | packages/nodes-logic | Yes | And / or / not, comparison, branch, selector |
@gausszhou/litegraph-nodes-strings | packages/nodes-strings | Yes | String concatenation, JSON, comparison, replace |
@gausszhou/litegraph-nodes-events | packages/nodes-events | Yes | Timer, delay, filter, log, branch |
@gausszhou/litegraph-nodes-input | packages/nodes-input | Yes | Gamepad input |
@gausszhou/litegraph-nodes-widget | packages/nodes-widget | Yes | Button, toggle, slider, knob, progress bar, panel |
@gausszhou/litegraph-nodes-graphics | packages/nodes-graphics | Yes | Curve plotting |
@gausszhou/litegraph-nodes-audio | packages/nodes-audio | Yes | Web Audio nodes |
@gausszhou/litegraph-nodes-midi | packages/nodes-midi | Yes | MIDI input/output and processing |
Node packs do not depend on each other, only on core; so you can install just the ones you need.
Three import strategies
1. Aggregate package: least code
import "@gausszhou/litegraph/style.css";
import { LGraph, LGraphCanvas, LiteGraph } from "@gausszhou/litegraph";
// The aggregate package installs all 10 node packs on import
const graph = new LGraph();
const canvas = new LGraphCanvas("#graph", graph);Good for demos, prototypes and editor-style apps. The trade-off is that every node pack ends up in your bundle.
2. core + on-demand packs: smallest bundle
import "@gausszhou/litegraph-core/style.css";
import { LGraph, LGraphCanvas, LiteGraph } from "@gausszhou/litegraph-core";
import installBasicNodes from "@gausszhou/litegraph-nodes-basic";
import installMathNodes from "@gausszhou/litegraph-nodes-math";
LiteGraph.use(installBasicNodes);
LiteGraph.use(installMathNodes);Node packs default-export install(LiteGraph); you can also call install(LiteGraph) directly, but LiteGraph.use() records installed plugins so repeated calls do not register twice.
Besides the default export, node packs export their node classes, which makes class-based creation easy:
import { ConstantNumber, Watch } from "@gausszhou/litegraph-nodes-basic";
const node = LiteGraph.createNode(ConstantNumber);
const watch = LiteGraph.createNode(Watch);3. UMD: <script> with no build tooling
After building, core is exposed as window.litegraph and packs as window.litegraphNodes<PascalCase> (for example litegraphNodesBasic, litegraphNodesAudio), with the default export on .default:
<link rel="stylesheet" href="litegraph.css" />
<script src="index.umd.cjs"></script>
<script src="nodes-basic/index.umd.cjs"></script>
<script>
const { LiteGraph } = window.litegraph;
const installBasic = window.litegraphNodesBasic.default;
installBasic(LiteGraph);
const graph = new window.litegraph.LGraph();
new window.litegraph.LGraphCanvas("#graph", graph);
</script>UMD builds externalize core into a global namespace, so multiple packs share the same LiteGraph instance; pnpm verify-umd loads them one by one in a VM and verifies exactly that.
Entry points and artifacts
Each package's main / types / exports point at src in source form for convenient workspace debugging; on publish publishConfig overrides them to dist:
| Package | Source entry | Publish entry | Style subpath |
|---|---|---|---|
| core | src/index.ts | dist/index.js + dist/index.d.ts | ./style.css → dist/litegraph.css |
| Aggregate package | src/index.ts | dist/index.js + dist/index.d.ts | ./style.css → dist/style.css |
| Node packs | src/index.ts | dist/index.js + dist/index.d.ts | none |
Builds produce both ESM (index.js) and UMD (index.umd.cjs); a pack's UMD marks @gausszhou/litegraph-core as external and maps it to the global litegraph, so core is never bundled twice. Type declarations are generated by tsc --emitDeclarationOnly.
Versions and publishing
- Every package is currently at
0.1.0and references the others withworkspace:*;pnpm pack/pnpm publishresolve those to concrete versions. - Nothing is published to npm before v1.0; the release plan (changesets, semantic versioning, migration guide) is in ROADMAP.md.
pnpm verify-packrunspnpm packfor each package and checks that the tarball containsdist,package.jsonand type declarations, so source or tests never leak into the package.
Which one to choose
| Scenario | Recommendation |
|---|---|
| Just want to see it work / build a demo | Aggregate package @gausszhou/litegraph |
| Production app using a handful of nodes | core + the 2–3 packs you need |
| Existing build chain, want to avoid bundling core twice | core + packs, and make sure core resolves only once |
| Static page with no bundler | UMD builds of core and the packs |
| Backend-only graph execution | Install only core (+ packs), never import the canvas |