From 4dd8d20dbee6767a0c30bd4f70a7bfe169200d3d Mon Sep 17 00:00:00 2001 From: Gregory Huczynski Date: Wed, 28 May 2014 09:34:17 +0100 Subject: [PATCH 1/2] Add `transform` option to call browserify.transform() --- README.md | 5 ++--- lib/index.js | 12 ++++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) 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..035dcf3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -17,6 +17,7 @@ function BrowserifyWriter(inputTree, options) { this.browserifyOptions = options.browserify || {}; this.bundleOptions = options.bundle || {}; 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) { From f65366f381c7681ab71c16c3a1c2d6367a12a7c7 Mon Sep 17 00:00:00 2001 From: Gregory Huczynski Date: Wed, 28 May 2014 09:35:05 +0100 Subject: [PATCH 2/2] Fix require option to have default empty [], not {} --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 035dcf3..c94036e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -16,7 +16,7 @@ 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; }