Skip to content

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 ​

PackageDirectoryDepends on coreContents
@gausszhou/litegraph-corepackages/core—Engine core: LiteGraph, LGraph, LGraphNode, LGraphCanvas, LLink, LGraphGroup, Subgraph, GraphInput, GraphOutput
@gausszhou/litegraphpackages/litegraphYesAggregate package: installs every node pack and re-exports all core APIs
@gausszhou/litegraph-nodes-basicpackages/nodes-basicYesConstants, watch, reroute, time, comparison, array access
@gausszhou/litegraph-nodes-mathpackages/nodes-mathYesMath operations, rounding, random, approximate equality
@gausszhou/litegraph-nodes-logicpackages/nodes-logicYesAnd / or / not, comparison, branch, selector
@gausszhou/litegraph-nodes-stringspackages/nodes-stringsYesString concatenation, JSON, comparison, replace
@gausszhou/litegraph-nodes-eventspackages/nodes-eventsYesTimer, delay, filter, log, branch
@gausszhou/litegraph-nodes-inputpackages/nodes-inputYesGamepad input
@gausszhou/litegraph-nodes-widgetpackages/nodes-widgetYesButton, toggle, slider, knob, progress bar, panel
@gausszhou/litegraph-nodes-graphicspackages/nodes-graphicsYesCurve plotting
@gausszhou/litegraph-nodes-audiopackages/nodes-audioYesWeb Audio nodes
@gausszhou/litegraph-nodes-midipackages/nodes-midiYesMIDI 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 ​

ts
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 ​

ts
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:

ts
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:

html
<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:

PackageSource entryPublish entryStyle subpath
coresrc/index.tsdist/index.js + dist/index.d.ts./style.css → dist/litegraph.css
Aggregate packagesrc/index.tsdist/index.js + dist/index.d.ts./style.css → dist/style.css
Node packssrc/index.tsdist/index.js + dist/index.d.tsnone

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.0 and references the others with workspace:*; pnpm pack / pnpm publish resolve 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-pack runs pnpm pack for each package and checks that the tarball contains dist, package.json and type declarations, so source or tests never leak into the package.

Which one to choose ​

ScenarioRecommendation
Just want to see it work / build a demoAggregate package @gausszhou/litegraph
Production app using a handful of nodescore + the 2–3 packs you need
Existing build chain, want to avoid bundling core twicecore + packs, and make sure core resolves only once
Static page with no bundlerUMD builds of core and the packs
Backend-only graph executionInstall only core (+ packs), never import the canvas

Released under the MIT License.