Browserify plugin to require() OpenGL Shading Language (GLSL) files
NOTE: Has not been tested on Node below version 6.0.0. Please report any bugs you may find.
npm install glslify-require
browserify index.js -p [ glslify-require ] > bundle.js
let browserify = require('browserify');
let glslifyRequire = require('glslify-require');
let bundle = browserify()
.plugin(glslifyRequire)
.add('index.js');
Now, you can use require() to retrieve GLSL source code as a JavaScript string:
var src = require('../path/to/my/glsl/file.glsl');
console.log(src);
Being fueled by glslify and glslify-deps, you can import and export GLSL modules. glslify-require will emit file events accordingly on browserify pipeline to keep your middleware up-to-date with dependencies.
Let's consider the following files:
index.js
var src = require('./main.glsl');
main.glsl
#pragma glslify: foo = require(./foo)
void main() {
bar = foo;
};
foo.glsl
struct Foo {
vec3 bar;
};
#pragma glslify: export(Foo)
The file event handler would be called for index.js, main.glsl and foo.glsl:
let browserify = require('browserify');
let glslifyRequire = require('glslify-require');
let bundle = browserify()
.plugin(glslifyRequire)
.add('index.js')
.on('file', function (file, id, parent) {
// called for index.js, main.glsl and foo.glsl
});
- Fork the main repository
- Code
- Implement tests using node-tap
- Issue a pull request keeping in mind that all pull requests must reference an issue in the issue queue
Apache-2.0 © Eric MORAND