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

wgslmin-wasm

v0.1.1

Published

WGSL minifier for WebGPU shaders - WebAssembly build

Downloads

15

Readme

wgslmin-wasm

WGSL minifier for WebGPU shaders - WebAssembly build.

This package provides a WASM build of the wgsl-minifier that runs in browsers and Node.js.

Installation

npm install wgslmin-wasm

Browser Usage

<script src="node_modules/wgslmin-wasm/wasm_exec.js"></script>
<script src="node_modules/wgslmin-wasm/lib/browser.js"></script>
<script>
  (async () => {
    await wgslmin.initialize({ wasmURL: 'node_modules/wgslmin-wasm/wgslmin.wasm' });

    const result = wgslmin.minify(`
      @vertex fn main() -> @builtin(position) vec4f {
        return vec4f(0.0);
      }
    `);

    console.log(result.code);
    // "@vertex fn main()->@builtin(position) vec4f{return vec4f(0.0);}"
  })();
</script>

ESM Usage

import { initialize, minify } from 'wgslmin-wasm';

await initialize({ wasmURL: '/path/to/wgslmin.wasm' });

const result = minify(source, {
  minifyWhitespace: true,
  minifyIdentifiers: true,
  minifySyntax: true,
});

Node.js Usage

const { initialize, minify } = require('wgslmin-wasm');

await initialize(); // Automatically finds wgslmin.wasm

const result = minify(source);
console.log(result.code);

API

initialize(options)

Initialize the WASM module. Must be called before minify().

interface InitializeOptions {
  wasmURL?: string | URL;           // Path or URL to wgslmin.wasm
  wasmModule?: WebAssembly.Module;  // Pre-compiled module
}

minify(source, options?)

Minify WGSL source code.

interface MinifyOptions {
  minifyWhitespace?: boolean;        // Remove whitespace (default: true)
  minifyIdentifiers?: boolean;       // Rename identifiers (default: true)
  minifySyntax?: boolean;            // Optimize syntax (default: true)
  mangleExternalBindings?: boolean;  // Mangle uniform/storage names (default: false)
  keepNames?: string[];              // Names to preserve from renaming
}

interface MinifyResult {
  code: string;           // Minified code
  errors: MinifyError[];  // Parse/minification errors
  originalSize: number;   // Input size in bytes
  minifiedSize: number;   // Output size in bytes
}

isInitialized()

Returns true if the WASM module is initialized.

version

The version of the minifier.

Options

minifyWhitespace

Remove unnecessary whitespace and newlines.

minifyIdentifiers

Rename local variables, function parameters, and helper functions to shorter names. Entry points and API-facing declarations are preserved.

minifySyntax

Apply syntax-level optimizations like numeric literal shortening.

mangleExternalBindings

Control how var<uniform> and var<storage> names are handled:

  • false (default): Original names are preserved in declarations, short aliases are used internally. This maintains compatibility with WebGPU's binding reflection APIs.
  • true: Names are mangled directly for smaller output, but breaks binding reflection.
// Input
const shader = `
@group(0) @binding(0) var<uniform> uniforms: f32;
fn getValue() -> f32 { return uniforms * 2.0; }
`;

// With mangleExternalBindings: false (default)
// Output: "@group(0) @binding(0) var<uniform> uniforms:f32;let a=uniforms;fn b()->f32{return a*2.0;}"

// With mangleExternalBindings: true
// Output: "@group(0) @binding(0) var<uniform> a:f32;fn b()->f32{return a*2.0;}"

keepNames

Array of identifier names that should not be renamed:

minify(source, {
  minifyIdentifiers: true,
  keepNames: ['myHelper', 'computeValue'],
});

Using with Bundlers

Vite

import { initialize, minify } from 'wgslmin-wasm';
import wasmURL from 'wgslmin-wasm/wgslmin.wasm?url';

await initialize({ wasmURL });

Webpack

import { initialize, minify } from 'wgslmin-wasm';

// Configure webpack to handle .wasm files
await initialize({ wasmURL: new URL('wgslmin-wasm/wgslmin.wasm', import.meta.url) });

Pre-compiling WASM

For better performance when creating multiple instances:

const wasmModule = await WebAssembly.compileStreaming(
  fetch('/wgslmin.wasm')
);

// Share module across workers
await initialize({ wasmModule });

Performance

  • WASM binary: ~3.6MB
  • Initialization: ~100ms (first load)
  • Transform: <1ms for typical shaders

License

MIT