Giter Club home page Giter Club logo

gulp-load-plugins's Introduction

gulp-load-plugins

npm

Loads in any gulp plugins and attaches them to the global scope, or an object of your choice.

Build Status

Install

$ npm install --save-dev gulp-load-plugins

Usage

Given a package.json file that has some dependencies within:

{
    "dependencies": {
        "gulp-jshint": "*",
        "gulp-concat": "*"
    }
}

Adding this into your Gulpfile.js:

var gulp = require('gulp');
var gulpLoadPlugins = require('gulp-load-plugins');
var plugins = gulpLoadPlugins();

Or, even shorter:

var plugins = require('gulp-load-plugins')();

Will result in the following happening (roughly, plugins are lazy loaded but in practice you won't notice any difference):

plugins.jshint = require('gulp-jshint');
plugins.concat = require('gulp-concat');

You can then use the plugins just like you would if you'd manually required them, but referring to them as plugins.name(), rather than just name().

This frees you up from having to manually require each gulp plugin.

Options

You can pass in an object of options that are shown below: (the values for the keys are the defaults):

gulpLoadPlugins({
    pattern: ['gulp-*', 'gulp.*'], // the glob(s) to search for
    config: 'package.json', // where to find the plugins, by default  searched up from process.cwd() 
    scope: ['dependencies', 'devDependencies', 'peerDependencies'], // which keys in the config to look within
    replaceString: /^gulp(-|\.)/, // what to remove from the name of the module when adding it to the context
    camelize: true, // if true, transforms hyphenated plugins names to camel case
    lazy: true, // whether the plugins should be lazy loaded on demand
    rename: {} // a mapping of plugins to rename
});

Renaming

From 0.8.0, you can pass in an object of mappings for renaming plugins. For example, imagine you want to load the gulp-ruby-sass plugin, but want to refer to it as just sass:

gulpLoadPlugins({
  rename: {
    'gulp-ruby-sass': 'sass'
  }
});

Lazy Loading

In 0.4.0 and prior, lazy loading used to only work with plugins that return a function. In newer versions though, lazy loading should work for any plugin. If you have a problem related to this please try disabling lazy loading and see if that fixes it. Feel free to open an issue on this repo too.

Credit

Credit largely goes to @sindresorhus for his load-grunt-plugins plugin. This plugin is almost identical, just tweaked slightly to work with Gulp and to expose the required plugins.

Changelog

0.8.0
  • add the ability to rename plugins that gulp-load-plugins loads in.
0.7.1
  • add files property to package.json so only required files are downloaded when installed - thanks @shinnn
0.7.0
  • support loading plugins with a dot in the name, such as gulp.spritesmith - thanks to @MRuy
  • upgrade multimatch to 1.0.0
0.6.0
  • Fix issues around plugin picking wrong package.json file - thanks @iliakan (see issue).
0.5.3
  • Show a nicer error if the plugin is unable to load any configuration and hence can't find any dependencies to load
0.5.2
  • Swap out globule for multimatch, thanks @sindresorhus.
0.5.1
  • Updated some internal dependencies which should see some small improvements - thanks @shinnn for this contribution.
0.5.0
  • improved lazy loading so it should work with plugins that don't just return a function. Thanks to @nfroidure for help with this.
0.4.0
  • plugins are lazy loaded for performance benefit. Thanks @julien-f for this.
0.3.0
  • turn the camelize option on by default
0.2.0
  • added camelize option, thanks @kombucha.
  • renamed to gulp-load-plugins.
0.1.1
  • add link to this repository into package.json (thanks @ben-eb).
0.1.0
  • move to gulpLoadplugins returning an object with the tasks define.
0.0.5
  • added replaceString option to configure exactly what gets replace when the plugin adds the module to the context
0.0.4
  • fixed keyword typo so plugin appears in search for gulp plugins
0.0.3
  • removed accidental console.log I'd left in
0.0.2
  • fixed accidentally missing a dependency out of package.json
0.0.1
  • initial release

gulp-load-plugins's People

Contributors

jackfranklin avatar julien-f avatar shinnn avatar iliakan avatar mruy avatar sindresorhus avatar ben-eb avatar nfroidure avatar passy avatar kombucha avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.