npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mlightcad/libredwg-web

v0.6.6

Published

A DWG/DXF JavaScript parser based on libredwg

Readme

libredwg-web

This is a DWG/DXF JavaScript parser based on libredwg. It can be used in browser and Node.js environments.

Build WebAssembly

Download and install emscripten according to this doc. Please make sure the following command is executed to activate PATH and other environment variables in the current terminal before building web assembly.

Download and install automake

Download and install pnpm

All can also be installed using homebrew:

brew install emscripten
brew install automake
brew install pnpm
# Activate PATH and other environment variables for emscripten in the current terminal if needed
source ./emsdk_env.sh

# run autogen
./autogen.sh

# change directory
cd bindings/javascript

# Install npm dependencies to build JavaScript bindings for libredwg
pnpm install

# Check for dependencies, available tools, and system configurations and prepare the software package for building libredwg on a specific system
pnpm build:prepare

# Compile and build libredwg
pnpm build:obj

# Use emscripten to build web assembly for libredwg
pnpm build:wasm

# Copy web assembly (wasm file and JavaScript glue code file) from build directory to distribution directory of this package
pnpm copy

# Build web assembly wrapper so that it is easier to use it
pnpm build

In order to reduce the size of wasm file, the following functionalities are not included by default when building web assembly.

  • write dwg file
  • read/write dxf file
  • import/export json file

If you want those functionalities, just modify command build:prepare defined in package.json and remove the following options.

  • disable-write
  • disable-json
  • disable-dxf

Usage

There are two approaches to use this package. No matter which approach to use, please do remember copying wasm file (libredwg.wasm) to the same folder as your JavaScript bundle file when deploying your application.

npm install @mlightcad/libredwg-web

Use Raw Web Assembly

The raw web assembly module (wasm file and JavaScript glue code file) is stored in folder wasm.

import { createModule } from "@mlightcad/libredwg-web/wasm/libredwg-web.js";

// Create libredwg module
const libredwg = await createModule();

// Store file content to one temporary file and read it
const fileName = 'tmp.dwg';
libredwg.FS.writeFile(
  fileName,
  new Uint8Array(fileContent)
);
const result = libredwg.dwg_read_file(fileName);
if (result.error != 0) {
  console.log('Failed to open dwg file with error code: ', result.error);
}
libredwg.FS.unlink(fileName);

// Get pointer to Dwg_Data
const data = result.data;

Use Web Assembly Wrapper

Web assembly wrapper is stored in folder dist. It provides one class LibreDwg to wrap the web assembly. This class provides

  • Method to convert dwg data to DwgDatabase instance with the strong type definition so that it is easy to use.
  • More methods that the raw web assembly API doesn't provide.
import { Dwg_File_Type, LibreDwg } from '@mlightcad/libredwg-web';
const libredwg = await LibreDwg.create();
const dwg = libredwg.dwg_read_data(fileContent, Dwg_File_Type.DWG);
const db = this.libredwg.convert(dwg);

// Affter conversion, 'dwg' isn't needed any more. So you can call
// function 'dwg_free' to free its memory.
this.libredwg.dwg_free(db);

Usage with node.js

import { Dwg_File_Type, LibreDwg } from '@mlightcad/libredwg-web'
// manually reference the wasm directory
const libredwg = await LibreDwg.create(
  './node_modules/@mlightcad/libredwg-web/wasm/'
)
…

Interfaces

There are two kinds of interfaces defined to access dwg/dxf drawing data.

Interfaces with prifix 'Dwg'

Those interfaces are much more easier to use with better data structure. It is quite similar to interfaces defined in project @mlightcad/dxf-json. Those interfaces describe most of commonly used objects in the dwg/dxf drawing.

Interfaces with prefix 'Dwg_'

Those interfaces are JavaScript version of structs defined in libredwg C++ code. Only a few structs have the correponding JavaScript interface. Most of them are defined to make it easier to convert libredwg data structure to DwgDatabase.

So it is recommend to use interfaces with prefix 'Dwg'.

Demo App

One demo app is provided in folder examples. You can run the following command to launch it.

pnpm demo