Registry / web-framework / wgsl-wasm-transpiler-bundler

wgsl-wasm-transpiler-bundler

JSON →
library0.0.1jsnpmunverified

A Rust-based WGSL shader compiler and cross-transpiler that converts WGSL to GLSL, HLSL, Metal, or SPIR-V. v0.0.1 is an early release with no regular release cadence yet. Differentiators: runs in Node.js and browser via WASM, single-function API, supports SPIR-V binary and assembly output. Requires manual WASM initialization via `init()` before any compilation calls. Competing with naga and glslang, but lighter and purely WGSL→others.

npm install wgsl-wasm-transpiler-bundler
INSTALL
IMPORT
SIG · WGSL-WASM-TRANSPIL
W
wgsl-wasm-transpiler-bundler
web-frameworkjavascriptv0.0.1
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.

compileShader
import { compileShader } from 'wgsl-wasm-transpiler-bundler'
import compileShader from 'wgsl-wasm-transpiler-bundler'
ESM; named export only. No default export.
init
import { init } from 'wgsl-wasm-transpiler-bundler'
const init = require('wgsl-wasm-transpiler-bundler')
Required before compileShader. Returns a promise in browser (await), sync in Node (call once).
getSupportedFormats
import { getSupportedFormats } from 'wgsl-wasm-transpiler-bundler'
Returns string array like ['wgsl','glsl','hlsl','metal','spirv','spirv-asm'].

Initialize WASM and compile a trivial WGSL fragment shader to GLSL.

import { init, compileShader } from 'wgsl-wasm-transpiler-bundler'; const wgsl = `@fragment fn main() -> @location(0) vec4<f32> { return vec4<f32>(1.0, 0.0, 0.0, 1.0); }`; // Browser: await init(); Node: init(); then use await init(); const glsl = compileShader(wgsl, 'glsl'); console.log(glsl);
Debug
Known issues
breakingCalling compileShader before init() throws: 'WASM not initialized' or panics.
fix
Always call init() (and await in browser) before any other API function.
affects: >=0.0.1
gotchainit() is synchronous in Node.js but asynchronous in browser. If you await in Node, it's fine, but forgetting await in browser will cause a runtime error.
fix
Use await init() in both environments; it works in Node too.
affects: >=0.0.1
gotchacompileShader throws on invalid WGSL or unsupported format. Unclear error messages may mention Rust panics.
fix
Validate WGSL before passing. Use getSupportedFormats() to check format. Wrap in try/catch.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: compileShader is not a function
Importing default instead of named export.
fix
Use import { compileShader } from 'wgsl-wasm-transpiler-bundler'
RuntimeError: unreachable (or WebAssembly.instantiate(): expected magic word)
WASM binary not loaded or init() not called properly.
fix
Ensure you are using the correct path to the WASM file and call init() with await.
Error: Unknown format: 'spirv_binary'
Using wrong format string; must be exactly one of the supported formats.
fix
Use 'spirv' for binary or 'spirv-asm' for text. Run getSupportedFormats() to see all.
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
45 hits · last 30 days
node
38
OpenAI (training)
2
Resources
wgsl-wasm-transpiler-bundler — npm install wgsl-wasm-transpiler-bundler · libregistry