diff --git a/lib/build-bundle.js b/lib/build-bundle.js index bdb1f3d..1f2e8f8 100644 --- a/lib/build-bundle.js +++ b/lib/build-bundle.js @@ -3,20 +3,7 @@ var browserify = require('browserify'); function compile(path, options) { - var bundle = browserify({ - noParse: options.noParse, - extensions: options.extensions, - resolve: options.resolve, - insertGlobals: options.insertGlobals, - detectGlobals: options.detectGlobals, - ignoreMissing: options.ignoreMissing, - bundleExternal: options.bundleExternal, - basedir: options.basedir, - debug: options.debug, - standalone: options.standalone || false, - cache: options.cache === 'dynamic' ? {} : undefined, - packageCache: options.cache === 'dynamic' ? {} : undefined - }); + var bundle = browserify(browserifyOptions(options)); if (options.plugins) { var plugins = options.plugins; // in the format options.plugins = [{plugin: plugin, options: options}, {plugin: plugin, options: options}, ... ] for(var i = 0; i < plugins.length; i++) { @@ -61,4 +48,46 @@ function compile(path, options) { return bundle; } +function browserifyOptions(middlewareOptions) { + var options = extend({}, middlewareOptions); + + omit(options, [ + 'external', + 'grep', + 'gzip', + 'ignore', + 'minify', + 'plugins', + 'postcompile', + 'postminify', + 'precompile', + 'preminify', + 'transform' + ]); + + return extend(options, { + standalone: middlewareOptions.standalone || false, + cache: middlewareOptions.cache === 'dynamic' ? {} : undefined, + packageCache: middlewareOptions.cache === 'dynamic' ? {} : undefined + }); +} + +function extend(object) { + for(var n = 1; n < arguments.length; n++) { + var o = arguments[n]; + + Object.keys(o).forEach(function (key) { + object[key] = o[key]; + }); + } + + return object; +} + +function omit(object, properties) { + properties.forEach(function (prop) { + delete object[prop]; + }); +} + module.exports = compile diff --git a/test/index.js b/test/index.js index 190f3e8..8e53f4a 100644 --- a/test/index.js +++ b/test/index.js @@ -158,6 +158,25 @@ app.get('/opt/no-minify.js', browserify(__dirname + '/directory/no-minify.js', { debug: false })); +app.get('/fullpaths.js', browserify(__dirname + '/directory/beep.js', { + cache: false, + gzip: false, + minify: { + mangle: false + }, + debug: true, + fullPaths: true +})); +app.get('/opt/fullpaths.js', browserify(__dirname + '/directory/beep.js', { + cache: true, + gzip: true, + minify: { + mangle: false + }, + debug: false, + fullPaths: true +})); + app.get('/opt/no-bundle-external.js', browserify(__dirname + '/directory/no-bundle-external.js', { bundleExternal: false, debug: false, @@ -410,6 +429,23 @@ function test(optimised, get, it) { }); }); }); + describe('passes other options to browserify', function () { + it('passes fullPaths', function (done) { + get('/fullpaths.js', optimised, function (err, res) { + if (err) return done(err); + assert(res.indexOf('test/directory/beep.js') != -1); + + vm.runInNewContext(res, { + console: { + log: function (res) { + assert.equal(res, 'BEEP!'); + done(); + } + } + }) + }); + }); + }); } describe('In NODE_ENV=development (default)', function () { @@ -454,4 +490,4 @@ describe('options.bundleExternal= false', function () { done(); }); }); -}); \ No newline at end of file +});