An esbuild plugin for importing GLSL, WGSL, frag, and vert shader files as strings with optional minification. Current stable version is 1.4.1, released with regular updates. It integrates tightly with esbuild's build process, supporting minify, resolveIncludes, and preserveLegalComments options. Unlike generic text loaders, it provides shader-aware features like include resolution and comment preservation. Requires Node >= 18 and esbuild 0.x.x, ships TypeScript type definitions, making it ideal for WebGL/WebGPU projects using esbuild.
npm install esbuild-plugin-glslVerified import paths — ran on the pinned version, not inferred.
Shows basic esbuild build with the glsl plugin, enabling minification and include resolution for shader files.
Use import statement and set module to ESM or use dynamic import.
Pin esbuild to 0.x.x in package.json.
Add a shaders.d.ts file with module declarations as shown in README.
Explicitly set minify: true in plugin options.
Run 'npm install esbuild-plugin-glsl' and ensure it's in package.json.
Use import { glsl } from 'esbuild-plugin-glsl'.