Registry / web-framework / shader-loader

shader-loader

JSON →
library1.3.1jsnpmunverified

A Webpack loader for GLSL shader files (.glsl, .vs, .fs) that supports shader chunk/inclusion syntax ($xxx). Current version 1.3.1, last updated 2017, no active development. Works with Webpack 2 and 3 (not Webpack 4+). Differentiates from raw-loader or glslify by allowing inclusion of GLSL chunks via $include syntax directly in shader source, inspired by cabbibo's ShaderLoader. Suitable for legacy projects using Three.js or similar with Webpack 2/3.

npm install shader-loader
INSTALL
IMPORT
SIG · SHADER-LOADER
S
shader-loader
web-frameworkjavascriptv1.3.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

default
✓ import vertexShader from 'shader.vs';
✗ const vertexShader = require('shader.vs');
ESM import works with Webpack 2/3 + babel or TypeScript; require works in CJS context.
none (loader)
✓ module.exports = { module: { rules: [ { test: /\.(glsl|vs|fs)$/, loader: 'shader-loader', options: { glsl: { chunkPath: 'path/to/chunks' } } } ] } };
✗ module.exports = { module: { rules: [ { test: /\.glsl$/, loader: 'shader-loader' } ] } };
Options are required for chunk resolution; without chunkPath, $include will fail.
none (chunk syntax)
✓ void main() { $noise }
✗ void main() { #include "noise.glsl" }
Uses $filename syntax, not C-style #include. File must be in chunkPath directory.

Sets up Webpack config to load .glsl/.vs/.fs files with shader-loader, including chunk path. Then imports a vertex shader in JavaScript.

// webpack.config.js const path = require('path'); module.exports = { entry: './src/index.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js' }, module: { rules: [ { test: /\.(glsl|vs|fs)$/, loader: 'shader-loader', options: { glsl: { chunkPath: path.resolve(__dirname, 'glsl/chunks') } } } ] } }; // src/vertex.vs void main() { gl_Position = vec4(position, 1.0); } // src/index.js import vertexShader from './vertex.vs'; console.log(vertexShader);
Debug
Known issues
breakingIncompatible with Webpack 4+ due to loader API changes.
fix
Use raw-loader or glslify for Webpack 4+; or stick with Webpack 2/3.
affects: >=1.3.1
deprecatedPackage has not been updated since 2017 and is no longer maintained.
fix
Consider migrating to glslify, raw-loader, or webpack-glsl-loader.
affects: all
gotchaShader chunks must be placed in the configured chunkPath directory; otherwise $include will silently fail.
fix
Set chunkPath in options and ensure chunk files (e.g., noise.glsl) exist there.
affects: all
gotchaThe loader only supports Webpack 2 and 3; not tested with Webpack 1.
fix
Use appropriate version of webpack (2.x or 3.x).
affects: >=1.0.0
Errors
Common errors & fixes
Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type.
Shader file is not being processed by shader-loader; webpack config missing or incorrect rule.
fix
Ensure webpack config includes { test: /\.(glsl|vs|fs)$/, loader: 'shader-loader' } and loader is installed.
ERROR in ./src/shader.vs Module build failed: Error: ENOENT: no such file or directory, open '.../glsl/chunks/snoise.glsl'
Chunk include ($snoise) cannot find the file in the specified chunkPath.
fix
Create the chunk file (e.g., snoise.glsl) in the directory specified by chunkPath option.
throw new Error('shader-loader only supports webpack 2 and 3');
Trying to use shader-loader with Webpack 4 or 5.
fix
Downgrade to webpack@3 or use an alternative loader like raw-loader.
Upgrade
Version history
1.3.1latest on npm
Audit
Dependencies
webpackrequiredWebpack loader; compatible with Webpack 2 and 3 only.
Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
shader-loader — npm install shader-loader · libregistry