glslify-deps
Walk the dependency graph of a glslify shader.
glslify-deps
is responsible for resolving your shader's dependencies and
applying their transforms before the actual source modification occurs. You may
notice some parallels here with browserify's
module-deps package.
While glslify-deps
is an "internal" package for glslify
, it may be useful
to use this package directly in specific cases, e.g. building a file tree
server-side but bundling the final shader on the client.
Module API
depper = glslifyDeps([options])
Creates a fresh glslify-deps
instance. Accepts the following options:
cwd
: the current working directory to resolve relative file paths from.readFile
: pass in a custom function reading files.resolve
: pass in a custom function for resolving require calls. It has the same signature as glsl-resolve.files
: a filename/source object mapping of files to prepopulate the file cache with. Useful for overriding particular file paths manually, most notably the "entry" file.
depper.transform(transform, [options])
Adds a new transform – should be used before calling depper.add
.
transform
may either be a string (which is resolved like a require
call),
or a function. More information on transforms can be found below.
depper.add(filename, [callback])
Adds a new file to the dependency graph.
depper.inline(source, basedir, [callback])
Adds a new inline file to the dependency graph, where source
is the GLSL
source to include and basedir
is the directory to pretend it's being
created in. A basedir
is required to properly resolve requires and transforms,
and defaults to process.cwd()
.
depper.on('file', cb(filename))
Emitted whenever a new file has been included in the dependency graph.
Example Output
Transform API
The transform API has changed since glslify 1.0 to make it more "vanilla".
module {}
As an example, here's glslify-hex rewritten using the new API:
var through =var regexLong = /#?/givar regexShort = /#?/gimoduleexports = transform{src = src}{return Stringn === -1? n + '.': n}
package.json
Transforms in Transforms now support options specified in package.json
: