Registry / development / minwgsl

minwgsl

JSON →
library1.0.3jsnpmunverified

A WGSL (WebGPU Shading Language) minifier written in Rust, compiled to WebAssembly for use in Node.js and browsers. Current stable version is 1.0.3, with frequent updates. It reduces WGSL shader size by removing comments, whitespace, and renaming variables. Key differentiators: Rust-based performance, TypeScript support, and works both in Node.js and browser environments via WebAssembly.

npm install minwgsl
INSTALL
IMPORT
SIG · MINWGSL
M
minwgsl
developmentjavascriptv1.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

minify
import { minify } from 'minwgsl'
const minify = require('minwgsl').minify
The package is ESM-only; CommonJS require will not work unless using dynamic import.
MinifyOptions
import type { MinifyOptions } from 'minwgsl'
import { MinifyOptions } from 'minwgsl'
MinifyOptions is a TypeScript type, so import type is recommended to avoid runtime inclusion.
default
import minwgsl from 'minwgsl'; minwgsl.minify(...)
import minwgsl from 'minwgsl'; minwgsl(...)
The default export is an object containing minify function; not callable directly.

Minifies a simple WGSL vertex shader using all available options.

import { minify } from 'minwgsl'; const wgsl = ` @vertex fn main(@builtin(vertex_index) vertexIndex: u32) -> @builtin(position) vec4<f32> { // This is a vertex shader let pos = vec2<f32>(0.0, 0.0); return vec4<f32>(pos, 0.0, 1.0); } `; const options = { removeComments: true, removeWhitespace: true, renameIdentifiers: true, }; const minified = minify(wgsl, options); console.log(minified.code); // Expected output: @vertex fn main(@builtin(vertex_index)vertexIndex:u32)->@builtin(position)vec4<f32>{let pos=vec2<f32>(0.0,0.0);return vec4<f32>(pos,0.0,1.0);}
Debug
Known issues
gotchaThe minifier may rename identifiers, which can break WGSL code that relies on reflection or string replacements.
fix
Set renameIdentifiers to false in options if you need to preserve original names.
affects: all
gotchaMinified code may not be valid WGSL if the input has errors; minifier assumes valid input.
fix
Validate WGSL before minification using a WGSL parser.
affects: all
gotchaThe package uses WebAssembly; browser usage requires a bundler or direct WASM loading.
fix
Use a bundler like Webpack or Vite, or load the WASM manually with @webassemblyjs.
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'minwgsl'
Package not installed or ESM module not resolved correctly.
fix
Run 'npm install minwgsl' and ensure your project uses ESM (set type: module in package.json or use .mjs file).
TypeError: minwgsl.minify is not a function
Importing default export instead of named export.
fix
Use 'import { minify } from 'minwgsl'' instead of 'import minwgsl from 'minwgsl''.
TypeError: minify is not a function
Forgetting to call minify with arguments or misconfigured import.
fix
Ensure you have imported minify correctly and call it with the WGSL string and options object.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
48 hits · last 30 days
node
42
Resources
minwgsl — npm install minwgsl · libregistry