gulp-resolve-dependencies
Resolve dependency directives in assets, e.g. @depend
(Juicer) or //= require
(Sprockets)). Inspired by grunt-concat-in-order. Useful in combination with gulp-concat.
Usage
First, install gulp-resolve-dependencies
as a development dependency:
npm install --save-dev gulp-resolve-dependencies
Then, add it to your gulpfile.js
(probably together with gulp-concat):
var resolveDependencies = require('gulp-resolve-dependencies');
var concat = require('gulp-concat');
gulp.task('js', function(){
gulp.src(['app/assets/js/main.js'])
.pipe(resolveDependencies({
pattern: /\* @requires [\s-]*(.*\.js)/g
}))
.on('error', function(err) {
console.log(err.message);
})
.pipe(concat())
.pipe(gulp.dest('dest/assets/js/'));
});
And use the directives in your JS files (dependencies can be nested, they are handled recursively):
(function(window, document, $, undefined) {
'use strict';
$(document).on('ready', function() {
$('.slideshow').slideshow();
});
})(window, document, jQuery);
Warning: This might not be very efficient (especially in case of nested dependencies). Some kind of caching mechanism could come in handy.
API
resolveDependencies(options)
options.pattern
Type: RegExp
The matching pattern (optional, defaults to ```/* @requires [\s-](.?.js)/g``).
options.log
Type: Boolean
Whether to log the resolved dependencies (optional, defaults to false
).