Skip to content

Instantly share code, notes, and snippets.

@silviopaganini
Last active January 3, 2016 05:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silviopaganini/8417474 to your computer and use it in GitHub Desktop.
Save silviopaganini/8417474 to your computer and use it in GitHub Desktop.
Gulp require snippet for all devDependencies
gulp = require('gulp');
pkg = require('./package.json');
for (k in pkg.devDependencies) {
v = pkg.devDependencies[k];
a = k.indexOf('gulp-') > -1 ? k.split('gulp-')[1] : k;
GLOBAL[a] = require(k);
}
@kewah
Copy link

kewah commented Jan 14, 2014

Same goal, but using matchdep

require('matchdep')
  .filterDev('gulp-*')
  .forEach(function(module) {
    global[module.replace(/^gulp-/, '')] = require(module);
  });

@silviopaganini
Copy link
Author

Coffeescript just in case

pkg = require './package.json'
GLOBAL[k.replace(/^gulp-/, '')] = require(k) for k, v of pkg.devDependencies

@stryju
Copy link

stryju commented Jan 14, 2014

@kewah why not filter it from package.json too?

require('matchdep')
  .filterDev('gulp-*', './package.json')
    .forEach(function(module) {
      global[module.replace(/^gulp-/, '')] = require(module);
    });

@kewah
Copy link

kewah commented Jan 14, 2014

@stryju by default it loads the nearest package.json

@stryju
Copy link

stryju commented Jan 14, 2014

@kewah ah, true! my bad :)

@bulkismaslom
Copy link

// load all gulp tasks matching the `gulp*` pattern to include gulp itself
require('matchdep')
    .filterDev('gulp*') //by default it loads the nearest package.json
    .forEach(function(module) {
        global[module.replace(/^gulp-/, '')] = require(module);
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment