mxgraph-js

mxgraph-js (ESM)

An ESM-first packaging of mxGraph tailored for Angular and modern bundlers. Core exports are side-effect free and initialized explicitly so apps can tree-shake what they need.

Install

npm install mxgraph-js

Or consume directly from GitHub (builds via prepare):

{
  "dependencies": {
    "mxgraph-js": "github:smilight/mxgraph-js#v4.2.2-esm"
  }
}

Core usage

import { mxGraph, mxClient, mxUtils } from 'mxgraph-js';
import { initMxGraph } from 'mxgraph-js/init';

await initMxGraph();
const container = document.getElementById('graph')!;
const graph = new mxGraph(container);
mxUtils.alert(`mxGraph ${mxClient.VERSION} ready`);

Per-symbol imports for tree-shaking

import { mxCellHighlight } from 'mxgraph-js/mxCellHighlight';
// no side effects; call init separately if you need the runtime

Each handler/utility entrypoint is side-effect free, so Angular 21+ production builds can drop unused mxGraph classes. All per-symbol entrypoints are auto-generated from the legacy sources during npm run build/npm run prepare, including when installed directly from GitHub.

Loading resources on demand

Optional bundles stay out of core imports:

import { loadBundle } from 'mxgraph-js/resources';
import { mxResources } from 'mxgraph-js';

const strings = await loadBundle('graph', 'de');
mxResources.parse(strings); // only when you need it

Available bundles: graph and editor with languages en, de, zh.

Angular 17+ example

A minimal Angular app lives in examples/angular/ (not published to npm):

Build & packaging

Development notes