capaj / require-globify

transform for browserify, which allows to require files with globbing expressions
MIT License
70 stars 11 forks source link

require-globify

Build Status Build Status Dependency Status devDependency Status

Transform for browserify, which allows to require files with globbing expressions.

Installation

require-globify

Usage

browserify -t require-globify entry.js > bundle.js

Example

The transform is triggered by adding an additional parameter to the classic require() call.

// just expand to multiple require calls, one for each matched file
require('./includes/*.js', {mode: 'expand'});

// return an object that maps each matched path to it's require() call
var hash = require('./includes/*.js', {mode: 'hash'});

Interface

The second parameter to require must be an object and supports the following keys:

mode [required]

Possible values are

resolve [optional, default:["path-reduce", "strip-ext"]]

The list of functions to determine the key of a matched file. You can provide a single value, but you can also provide an array of these values. In the case an array is provided, the resolvers are executed in order to determine the final key.

Possible values are

options [optional, default:{}]

This allows options to be provided to node-glob, which is used internally to find matching files.

ext [deprecated, optional, default:false]

This option is replaced by resolve: 'strip-ext', but remains supported until version 2.0.0. WARNING: Backwards compatibility is not available in combination with the newer "resolve" option.

glob [deprecated]

This option is replaced by mode: 'expand', but remains supported until version 2.0.0

hash [deprecated]

This option is replaced by mode: 'hash' and resolve: ['path', 'strip-ext'], but remains supported until version 2.0.0

Credits

Original concept from Jiří špác, completely reimplemented by Adriaan Callaerts(@call-a3).
Hashing with paths implemented by Pat Collins(@patcoll).

License

MIT

Changelog