# browser-pack-flat Bundle browserify modules into a single scope, a la rollup. Caveats: - Modules are executed fully, one after another, instead of inline. This is a potential difference from Node.js and the default browserify behaviour. Usually this does not matter, but rarely the order that some things are executed in may change. - This rewrites `require()` calls to simple variable assignments. If a module wraps `require()` somehow it probably will not work. In practice this is quite rare. - Using `factor-bundle` to split output code into separate files will not work with this plugin. ## Install ```bash npm install --save-dev browser-pack-flat ``` ## Usage ```bash browserify /path/to/app.js | browser-unpack | browser-pack-flat ``` Or as a plugin: ```bash browserify /path/to/app.js -p browser-pack-flat ``` The plugin replaces the `browser-pack` module used by default by browserify. With the Node API: ```js var browserify = require('browserify') var packFlat = require('browser-pack-flat') browserify({ entries: './src/app.js' }) .plugin(packFlat, { /* options */ }) .bundle() .pipe(fs.createWriteStream('bundle.js')) ``` ## What exactly? browserify uses [browser-pack](https://github.com/browserify/browser-pack) to output a bundle. browser-pack uses a small `require`-like runtime and wraps modules in functions to get a module loading behaviour that's almost identical to Node.js. However this resolution can take a few milliseconds across an entire bundle. Input: ```js var unique = require('uniq'); var data = [1, 2, 2, 3, 4, 5, 5, 5, 6]; console.log(unique(data)); ``` With browser-pack, this bundle would output: ```js (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o