wonder-glsl-compiler

raw JSON →
0.1.17 verified Fri May 01 auth: no javascript

A GLSL compiler library for transforming GLSL shaders at runtime. Version 0.1.17 is the latest stable release with irregular updates. It provides shader compilation and optimization for WebGL/WebGPU applications. Differentiates by offering a lightweight, pure JavaScript implementation without external GPU dependencies, suitable for shader preprocessing in build tools or runtime environments.

error TypeError: wonderGLSLCompiler.compile is not a function
cause Importing default as named function incorrectly.
fix
Use default import: import wonderGLSLCompiler from 'wonder-glsl-compiler';
error Cannot find module 'wonder-glsl-compiler'
cause Package not installed or incorrect import path in TypeScript.
fix
Run npm install wonder-glsl-compiler and ensure tsconfig.json resolves modules.
error Error: GLSL compilation failed with errors
cause GLSL shader code has syntax or semantics errors.
fix
Check the shader code for typos or unsupported features.
gotcha The library does not validate GLSL syntax; invalid shaders may cause runtime errors.
fix Pre-validate shaders using a GLSL linter before compilation.
deprecated Older versions may rely on deprecated APIs removed in Node.js 18+.
fix Upgrade to 0.1.17 or later.
gotcha Only supports immediate mode compilation; no caching or incremental rebuilds.
fix Implement manual caching if compiling multiple shaders.
npm install wonder-glsl-compiler
yarn add wonder-glsl-compiler
pnpm add wonder-glsl-compiler

Demonstrates basic usage of the compiler: import, compile a simple GLSL shader, and log the output.

import wonderGLSLCompiler from 'wonder-glsl-compiler';
const glslCode = 'void main() { gl_FragColor = vec4(1.0); }';
const result = wonderGLSLCompiler.compile(glslCode);
console.log(result.output);