Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added contentfilter option to bundle. #248

Closed
wants to merge 1 commit into from

2 participants

@statico

This is exactly what I'm looking for WRT #247

I know browserify-2.0 is right around the corner, but this is super-useful for us.

Thanks!

@substack
Owner

v2 is out so this patch no longer applies. Soon the bundle pipeline will be exposed to userland and you can just hook a through stream into that.

@substack substack closed this
@statico

Wonderful, thanks! (cc @jspiro)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 1, 2012
  1. @statico
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 0 deletions.
  1. +6 −0 index.js
  2. +10 −0 lib/wrap.js
View
6 index.js
@@ -94,6 +94,12 @@ var exports = module.exports = function (entryFile, opts) {
});
}
+ if (opts.contentfilter) {
+ w.register('content', function (target, body) {
+ return opts.contentfilter(target, body);
+ });
+ }
+
w.ignore(opts.ignore || []);
if (opts.require) {
View
10 lib/wrap.js
@@ -47,6 +47,7 @@ function Wrap (opts) {
this.pathFilters = [];
this.postFilters = [];
this.preFilters = [];
+ this.contentFilters = [];
this.aliases = {};
this._checkedPackages = {};
this.errors = {};
@@ -121,6 +122,9 @@ Wrap.prototype.register = function (ext, fn) {
else if (ext === 'path') {
this.pathFilters.push(fn);
}
+ else if (ext === 'content') {
+ this.contentFilters.push(fn);
+ }
else if (fn) {
this.extensions.push(ext);
this.filters.push(function (body, file) {
@@ -365,6 +369,9 @@ Wrap.prototype.wrap = function (target, body) {
return JSON.stringify(target);
})
.replace(/\$body/, function () {
+ self.contentFilters.forEach((function (fn) {
+ body = fn.call(self, target, body);
+ }).bind(self));
return self.debug
? JSON.stringify(body + '\n//@ sourceURL=' + target)
: body
@@ -380,6 +387,9 @@ Wrap.prototype.wrapEntry = function (target, body) {
return JSON.stringify(target)
})
.replace(/\$body/, function () {
+ self.contentFilters.forEach((function (fn) {
+ body = fn.call(self, target, body);
+ }).bind(self));
return self.debug
? JSON.stringify(body + '\n//@ sourceURL=' + target)
: body
Something went wrong with that request. Please try again.