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

vite-plugin-cpp-loader

v2.0.3

Published

Vite plugin — import .cpp files as typed ES modules compiled to WebAssembly via Emscripten

Readme

vite-cpp-loader

Import .cpp files directly into TypeScript. Functions compile to WebAssembly and are callable with full type safety.

Prerequisites

Emscripten must be installed and em++ available in your PATH.

macOS:

brew install emscripten

Linux / macOS (via emsdk):

git clone https://github.com/emscripten-core/emsdk.git
cd emsdk && ./emsdk install latest && ./emsdk activate latest
source ./emsdk_env.sh

Windows:

git clone https://github.com/emscripten-core/emsdk.git
cd emsdk && emsdk install latest && emsdk activate latest && emsdk_env.bat

Installation

npm install vite-plugin-cpp-loader --save-dev

Setup

// vite.config.ts
import { defineConfig } from 'vite';
import cppLoader from 'vite-plugin-cpp-loader';

export default defineConfig({
  plugins: [cppLoader()]
});

Usage

Write plain C++ — no Emscripten boilerplate required. All top-level non-static functions are automatically exported.

math.cpp

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

main.ts

import { add } from './math.cpp';

add(2, 3); // 5

If you only want to export a subset of functions, mark the ones you want to keep internal as static and they will be excluded.

Type safety

Types are inferred from your C++ signatures:

import { add } from './math.cpp';

add(2, 3);     // ✅
add("2", 3);   // ❌ Argument of type 'string' is not assignable to parameter of type 'number'

Supported C++ → TypeScript mappings:

| C++ | TypeScript | |-----|------------| | int, float, double, long, short, unsigned | number | | int32_t, uint32_t, int64_t, uint64_t, size_t | number | | bool | boolean | | std::string, const char* | string | | void | void | | emscripten::val | any |

Complex types (STL containers, custom classes) are not supported as parameters or return types.

Options

cppLoader({
  emccArgs: ['-sASSERTIONS=1'],   // extra flags passed to em++
  optimizationLevel: 'O3',         // default: 'O2'
  cacheDir: '.my-wasm-cache',      // default: 'node_modules/.cpp-wasm'
  setupVSCode: false,              // disable auto-generation of .vscode/c_cpp_properties.json
})

Troubleshooting

em++ not found — make sure Emscripten is installed and in your PATH. If you installed via emsdk, run source ./emsdk_env.sh before starting the dev server.

License

MIT