diff --git a/README.md b/README.md index bd8ade7..98deefb 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,8 @@ tree = browserify(tree, options); * `outputFile`: (default `"./browserify.js"`) Output file * `browserify` : (default `{}`) Options passed to the [browserify constructor](https://github.com/substack/node-browserify#var-b--browserifyfiles-or-opts) * `bundle`: (default `{}`) Options passed to [browserify bundle method](https://github.com/substack/node-browserify#bbundleopts-cb) -* `require`: (default []) An array of file, option pairs -passed to [browserify require -method](https://github.com/substack/node-browserify#brequirefile-opts) +* `require`: (default []) An array of file, option pairs passed to [browserify require method](https://github.com/substack/node-browserify#brequirefile-opts) +* `transform`: (default []) An array of option, transform pairs passed to [browserify transform method](https://github.com/substack/node-browserify#btransformopts-tr) ## Changelog diff --git a/lib/index.js b/lib/index.js index c5023cc..c94036e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -16,7 +16,8 @@ function BrowserifyWriter(inputTree, options) { this.outputFile = options.outputFile || '/browserify.js'; this.browserifyOptions = options.browserify || {}; this.bundleOptions = options.bundle || {}; - this.requireOptions = options.require || {}; + this.requireOptions = options.require || []; + this.transformOptions = options.transform || []; this.inputTree = inputTree; } @@ -29,6 +30,7 @@ BrowserifyWriter.prototype.write = function (readTree, destDir) { var browserifyOptions = this.browserifyOptions; var bundleOptions = this.bundleOptions; var requireOptions = this.requireOptions; + var transformOptions = this.transformOptions; return readTree(this.inputTree).then(function (srcDir) { mkdirp.sync(path.join(destDir, path.dirname(outputFile))); @@ -36,13 +38,19 @@ BrowserifyWriter.prototype.write = function (readTree, destDir) { browserifyOptions.basedir = srcDir; var b = browserify(browserifyOptions); - for (var i = 0; i < entries.length; i++) { + var i; + for (i = 0; i < entries.length; i++) { b.add(entries[i]); } - for(var i = 0; i < requireOptions.length; i++){ + + for(i = 0; i < requireOptions.length; i++){ b.require.apply(b, requireOptions[i]); } + for(i = 0; i < transformOptions.length; i++){ + b.transform.apply(b, transformOptions[i]); + } + return new RSVP.Promise(function (resolve, reject) { b.bundle(bundleOptions, function (err, data) { if (err) {