0.1.0 • Published 10 years ago

broccoli-load-plugins v0.1.0

Weekly downloads
-
License
-
Repository
-
Last release
10 years ago

broccoli-load-plugins Build Status

Automatically loads broccoli plugins and attaches them to an object of your choice or the global scope.

Usage

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

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

{
  "dependencies": {
    "broccoli-static-compiler": "*",
    "broccoli-uglify-js": "*",
    "broccoli-template": "*"
  }
}

Adding this into your Broccolifile.js:

var broccoliLoadPlugins = require('broccoli-load-plugins');
var plugins = broccoliLoadPlugins();

Or, even shorter:

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

Will result in the following happening:

plugins.staticCompiler = require('broccoli-static-compiler');
plugins.uglifyJs = require('broccoli-uglify-js');
plugins.template = require('broccoli-template');

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

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

Options

You can pass in an object of options (the shown options are the defaults):

broccoliLoadPlugins({
  // the glob to search for
  pattern: 'broccoli-*',

  // where to find the plugins
  config: 'package.json',

  // which keys in the config to look within
  scope: ['dependencies', 'devDependencies', 'peerDependencies'],

  // what to remove from the name of the module when adding it to the context
  replaceString: 'broccoli-',

  // if true, transforms hyphenated plugins names to camel case
  camelize: true
});

Credit

Credit largely goes to @jackfranklin for his gulp-load-plugins module. This module is almost identical, just tweaked slightly to work with Broccoli.