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

cpp-loader

v1.0.0

Published

> A C++ loader for Webpack

Readme

cpp-loader

A C++ loader for Webpack

Requirements

  • You will need a version of both Clang and the Libclang with a decent C++17 support to install the loader.
  • At runtime, the em++ toolchain must be located inside your PATH for this loader to work properly.

If you've installed emscripten for the first time, the first compilation will be VERY slow. Subsequent compilations will be much faster.

Usage

index.js:

import { addition } from './lib.cc';

console.log(addition(2, 2));
console.log(range(10, 100));

lib.cc:

#include <vector>

int addition(int a, int b)
{
    return a + b;
}

std::vector<int> range(int from, int to)
{
    std::vector<int> r;

    for (auto t = from; t < to; ++t)
        r.emplace_back(t);

    return r;
}

How does it work?

  • First we parse the source file using the LibClang. We extract all the exported symbols from the main file (so no static function, for example).
  • For each of these functions and classes, we add a new embind entry at the bottom of the original source file, in order to automatically expose it to Javascript.
  • In order to add support for the STL data types out-of-the box, we also wrap all the function (and class function) pointers into the emmagic wrappers, which automatically deal with this for us.
  • Finally, the resulting file is compiled via emscripten into asm.js, and webpack can bundle it like any other javascript package.

Limitations

The main limitation is the implementation; most of the following issues could be solved by improving the loader:

  • Not all STL containers are supported.

    Possible fix: They just have to be implemented in emmagic.

  • Currently only works on Windows because I'm lazy.

    Possible fix: I need to be less lazy. Also, the build script shouldn't use bashisms.

  • The compilation output needs to be asm.js rather than WebAssembly.

    Possible fix: An easy fix would be to generate an extra file instead of javascript, and tell Webpack not to bundle it inside the final output. I'm not entirely sure how to make this happen with Webpack, so if someone can investigate this, it would be really helpful.

  • A separate compilation is done for each file to compile. It's quite inefficient, because it means that if two files depend on the same common code, this code will be duplicated inside each asm.js module, and will be stored twice in the resulting bundle.

    Possible fix: Fixing this would require to process all the dependencies from all the files at once, and then to process all the C++ files all at once (effectively linking them together).

  • The code has to be compiled with the C++17 standard.

    Possible fix: Unfortunately there's no easy fix for this one; emmagic does its magic through a lot of metaprogramming hacks that have been greatly simplified with the latest standards, and I can't imagine doing without it. Fortunately the C++ standards are mostly backward-compatible, and the compilation only needs to run a single computer (cause after that it becomes pure Javascript!), so it shouldn't be a big issue.