require-graph
A tiny library for building/serving dependencies for client-side assets (JavaScript, HTML templates, etc.). Licensed under MIT.
Installation
npm install require-graph
Examples
Suppose you have some JavaScript files that depend on each other:
a.js
depends onb.js
andc.js
b.js
depends onc.js
andd.js
c.js
depends ond.js
a.js
:
/** @depends * b.js * c.js */ messages;
b.js
:
/** @depends * c.js * d.js */ messages;
c.js
:
/** @depends * d.js */ messages;
d.js
:
var messages = 'I am file D!' ;
After defining all the dependencies, you can concatenate them at runtime (or build time, or whenever-you-want-time):
var GraphBuilder = path = builder = root = '/path/to/files'; builder;
Directories as dependencies
You can also specify a relative directory as a dependency, in which case all files in that directory (recursively) will be set as dependencies. For example:
/** @depends
* this/file.js
* that/directory
*/
buildGraph()
Options
Remove require-graph specific headers (the /** @depends...*/
blocks):
var options = removeHeaders: true;build;
Do something to the file's contents:
var options = { var stat = fs; return '// last modified on ' + statmtime + '\n' + contents; };build;
Control which files are parsed:
var options = { // only parse javascript files return /\.js$/; };build;
Development
git clone git@github.com:tmont/require-graph.gitcd require-graphnpm installnpm test