Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transform option #1

Merged
merged 2 commits into from
Aug 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 11 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -29,20 +30,27 @@ 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)));

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) {
Expand Down