The open-source gcode-preview library broke its API in 3.0 alpha to become a proper ES module, and added streaming rendering, adaptive layer height display and multi-color support for MMU, AMS and ERCF files.
Every site that lets you upload a G-code file needs a preview, and until recently the options were a heavyweight desktop slicer or someone's abandoned jQuery widget. The open-source gcode-preview library has grown into the credible option for doing it in a browser, and its 3.0 alpha just made the decision that will annoy people in the short term and help them later: it is now ES-module-only.
What changed in 3.0
The library, maintained by Remco Veldkamp and Sophie de Ziel under the xyz-tools GitHub organization, dropped the UMD build, the global GCodePreview variable and deep import paths like gcode-preview/dist/gcode-preview.es.js. You import from the package name, and that is the whole story. The stable 2.x line stays on npm for anyone who cannot move yet. The 3.0 alpha also typechecks its published declarations against both TypeScript 6 and 5.9 across the supported module resolution modes, which is the kind of unglamorous packaging work that separates a maintained library from a weekend project.
The parser itself covers the commands that matter for a preview: G0 and G1 moves, G2 and G3 arcs including files run through ArcWelder, homing, the G38 probe family and G92 offsets. It detects which slicer produced a file (the PrusaSlicer family, Cura, Simplify3D and Slic3r) and pulls embedded thumbnails out of PrusaSlicer output. It deliberately does not support G92.2 and G92.3, and undocumented commands parse without crashing, which is the right behavior for a viewer that has to face whatever a slicer emitted.
The features that actually get used
Two additions matter more than the module format. First, the library reads the standalone ;WIDTH: and ;HEIGHT: comments that PrusaSlicer, SuperSlicer, OrcaSlicer and Bambu Studio emit, and renders each path at its true dimensions. A print sliced with adaptive layer heights finally previews the way it will print instead of as a uniform stack of lines. Second, files stream in from a ReadableStream and render progressively, so a huge G-code file builds up on screen instead of freezing the tab while it parses. Multi-color rendering maps T0 through T7 to per-tool colors, and the supported systems listed in the docs cover the realistic cases: Prusa MMU and XL, Bambu Lab AMS and AMS lite, ERCF, IDEX machines, tool changers and virtual tools for color mixing.
It is built with TypeScript on top of three.js (anything from 0.166 up to but not including 0.186), renders extrusion as tube geometry by default with a flat-line fallback, and ships working examples for Vue, React and Svelte. MIT licensed, no telemetry, nothing added to your page beyond the canvas you hand it. A fork worth knowing about exists too: ChestnutLabs moved the parser into a Web Worker, added .bgcode decoding and layer scrubbing, and colors toolpaths by feature role where the slicer recorded one. If your need is a dev tool rather than an embedded preview, that fork is worth a look.
Why this is a good time to adopt it
The 2.x to 3.0 migration is the moment to switch, because the alpha is where breaking changes are free. If you maintain a print-history site, a farm dashboard or a model marketplace with a web slicer, a maintained MIT viewer that handles adaptive heights and streaming covers most of the edge cases that used to justify writing your own parser. Try gcode-preview@alpha, keep 2.x pinned until your tests pass, and report the dialect quirks you hit back upstream, since slicer detection quality is exactly the thing community bug reports improve.
Comments (0)
No comments yet. Be the first!
Leave a Comment