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.
npm install mxgraph-js
Or consume directly from GitHub (builds via prepare):
{
"dependencies": {
"mxgraph-js": "github:smilight/mxgraph-js#v4.2.2-esm"
}
}
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`);
initMxGraph once to load the legacy bundle (dist/resources/mxgraph.js) and wire exports.initMxGraph({ resourcesBaseUrl: '/static/mxgraph/' }).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.
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.
A minimal Angular app lives in examples/angular/ (not published to npm):
src/main.ts calls initMxGraph() once before bootstrapping.AppComponent renders a basic graph without loading optional resources.npm install inside the example, then npm run build.npm run build – cleans, compiles TypeScript (ESM + d.ts + source maps), and bundles the legacy mxGraph sources plus runtime assets into dist/resources/.npm pack produces a tarball containing only dist/, README.md, and LICENSE (see package.json#files).dist/init.* and dist/resources/** for effective tree-shaking.javascript/src/js; they are concatenated in scripts/build-legacy.mjs using the order from index.html.src/ (core exports, init loader, resources helpers) with generated TypeScript declarations.