{"name":"factor-bundle","version":"2.2.2","description":"factor browser-pack bundles into common shared bundles","main":"index.js","bin":{"factor-bundle":"bin/cmd.js"},"dependencies":{"JSONStream":"~0.8.4","browser-pack":"^3.1.1","defined":"0.0.0","deps-topo-sort":"~0.2.1","inherits":"^2.0.1","minimist":"~0.2.0","nub":"0.0.0","reversepoint":"~0.2.0","stream-combiner":"~0.2.1","through2":"^0.5.1","xtend":"^4.0.0"},"devDependencies":{"browser-unpack":"~0.2.0","browserify":"^5.11.0","concat-stream":"^1.4.6","mkdirp":"~0.5.0","module-deps":"^2.1.0","tape":"^2.13.0","through":"^2.3.4"},"scripts":{"test":"tape test/*.js"},"repository":{"type":"git","url":"git://github.com/substack/factor-bundle.git"},"homepage":"https://github.com/substack/factor-bundle","keywords":["browserify","browserify-tool","browserify-plugin","bundle","browser-pack"],"author":{"name":"James Halliday","email":"mail@substack.net","url":"http://substack.net"},"license":"MIT","gitHead":"0ec7e40a45210d8bf8bb8f92c01091d216dc77ad","bugs":{"url":"https://github.com/substack/factor-bundle/issues"},"_id":"factor-bundle@2.2.2","_shasum":"52add7320f45b51500a9f10fa3f9f511d1edb202","_from":".","_npmVersion":"2.0.2","_nodeVersion":"0.10.31","_npmUser":{"name":"substack","email":"mail@substack.net"},"maintainers":[{"name":"substack","email":"mail@substack.net"},{"name":"terinjokes","email":"terinjokes@gmail.com"}],"dist":{"shasum":"52add7320f45b51500a9f10fa3f9f511d1edb202","tarball":"http://registry-npm.ywwl.com/factor-bundle/download/factor-bundle-2.2.2.tgz","integrity":"sha512-ytTQlmQgYpo0t4HAgTKgFW5CvlSWukIx+5/Kys3GS0skfX9hPo3yw4VUBKilCKltfgsU5RHTctLGy4NU31D5oA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCID/r+H4vIRyXGV0EUCGoGzf6uunl5b5hck3Vm/BsuQVNAiEAkQvFITILWc4mBYmka/owOdjmXMkRQZPQfFa7hpTkDAk="}],"size":7350,"noattachment":false,"key":"/factor-bundle/-/factor-bundle-2.2.2.tgz"},"directories":{},"readme":"# factor-bundle\n\nfactor [browser-pack](https://npmjs.org/package/browser-pack) bundles into a\ncommon bundle and entry-specific bundles\n\n[![build status](https://secure.travis-ci.org/substack/factor-bundle.png)](http://travis-ci.org/substack/factor-bundle)\n\n# example\n\nx.js:\n\n``` js\nvar z = require('./z.js');\nvar w = require('./w.js');\nconsole.log(z(5) * w(2));\n```\n\ny.js:\n\n``` js\nvar z = require('./z.js');\nconsole.log(z(2) + 111);\n```\n\nz.js:\n\n``` js\nmodule.exports = function (n) { return n * 111 }\n```\n\nw.js:\n\n``` js\nmodule.exports = function (n) { return n * 50 }\n```\n\nNow run factor-bundle as a plugin (new in browserify 3.28.0):\n\n``` sh\nbrowserify x.js y.js -p [ factor-bundle -o bundle/x.js -o bundle/y.js ] \\\n  -o bundle/common.js\n```\n\nor you can pipe [module-deps](https://npmjs.org/package/module-deps) json\ndirectly into the `factor-bundle` command:\n\n``` sh\n$ module-deps x.js y.js | factor-bundle \\\n  x.js -o bundle/x.js \\\n  y.js -o bundle/y.js \\\n  > bundle/common.js\n```\n\nor factor out an existing bundle already compiled by browserify:\n\n``` sh\n$ browserify x.js y.js > bundle.js\n$ browser-unpack < bundle.js | factor-bundle \\\n  x.js -o bundle/x.js \\\n  y.js -o bundle/y.js \\\n  > bundle/common.js\n```\n\nWhichever one of these 3 options, you take, you can now have 2 pages, each with\na different combination of script tags but with all the common modules factored\nout into a `common.js` to avoid transferring the same code multiple times:\n\n``` html\n<script src=\"/bundle/common.js\"></script>\n<script src=\"/bundle/x.js\"></script>\n```\n\n``` html\n<script src=\"/bundle/common.js\"></script>\n<script src=\"/bundle/y.js\"></script>\n```\n\nto verify this works from node you can do:\n\n```\n$ cat bundle/common.js bundle/x.js | node\n55500\n$ cat bundle/common.js bundle/y.js | node\n333\n```\n\n## command-line outpipe example\n\nWe can pipe each output file through some other processes. Here we'll do\nminification with uglify compression with gzip:\n\n``` sh\nbrowserify files/*.js \\\n    -p [ factor-bundle -o 'uglifyjs -cm | gzip > bundle/`basename $FILE`.gz' ] \\\n    | uglifyjs -cm | gzip > bundle/common.js.gz\n```\n\n## api plugin example\n\nIf you prefer you can use the factor-bundle plugin api directly in code:\n\n``` js\nvar browserify = require('browserify');\nvar fs = require('fs');\n\nvar files = [ './files/x.js', './files/y.js' ];\nvar b = browserify(files);\nb.plugin('factor-bundle', { outputs: [ 'bundle/x.js', 'bundle/y.js' ] });\nb.bundle().pipe(fs.createWriteStream('bundle/common.js'));\n```\n\nor instead of writing to files you can output to writable streams:\n\n``` js\nvar browserify = require('browserify');\nvar concat = require('concat-stream');\n\nvar files = [ './files/x.js', './files/y.js' ];\nvar b = browserify(files);\n\nb.plugin('factor-bundle', { outputs: [ write('x'), write('y') ] });\nb.bundle().pipe(write('common'));\n\nfunction write (name) {\n    return concat(function (body) {\n        console.log('// ----- ' + name + ' -----');\n        console.log(body.toString('utf8'));\n    });\n}\n```\n\n# usage\n\nYou can use factor-bundle as a browserify plugin:\n\n```\nbrowserify -p [ factor-bundle OPTIONS ]\n\nwhere OPTIONS are:\n\n  -o  Output FILE or CMD that maps to a corresponding entry file at the same\n      index. CMDs are executed with $FILE set to the corresponding input file.\n      Optionally specify a function that returns a valid value for this argument.\n \n  -e  Entry file to use, overriding the entry files listed in the original\n      bundle.\n\n```\n\nor you can use the command:\n\n```\nusage: factor-bundle [ x.js -o bundle/x.js ... ] > bundle/common.js\n\nRead `module-deps` json output from stdin, factoring each entry file out into\nthe corresponding output file (-o).\n\n  -o FILE, -o CMD\n\n    Write output to FILE or CMD. CMD is distinguished from FILE by the presence\n    of one or more `>` or `|` characters. For example, use:\n    \n      factor-bundle browser/a.js browser/b.js \\\n        -o bundle/a.js -o bundle/b.js\n    \n    to write to a FILE. And do something like:\n\n      factor-bundle browser/*.js \\\n        -o 'uglifyjs -cm | gzip > bundle/`basename $FILE`.gz'\n\n    to use a CMD. In the CMD, $FILE is set to the corresponding input file path.\n\n    If there is a trailing unpaired `-o`, that file will be used for the common\n    bundle output. Otherwise, the final bundle is written to stdout.\n\n```\n\n# methods\n\n``` js\nvar factor = require('factor-bundle')\n```\n\n## var fr = factor(files, opts={})\n\nReturn a transform stream `tr` that factors the array of entry path strings\n`files` out into bundle files. The input format that `fr` expects is described\nin the [module-deps package](https://npmjs.org/package/module-deps).\n\nThe output format for `fr` and each of the `fr` sub-streams given by each\n`'stream'` event is also in the\n[module-deps](https://npmjs.org/package/module-deps) format.\n\n`opts.o` or `opts.outputs` should be an array that pairs up with the `files` array to specify\nwhere each bundle output for each entry file should be written. The elements in\n`opts.o` can be string filenames, writable streams, or functions that return a\nstring filename or writable stream.\n\n`opts.entries` or `opts.e` should be the array of entry files to create\na page-specific bundle for each file. If you don't pass in an `opts.entries`,\nthis information is gathered from browserify itself.\n\nThe files held in common among `> opts.threshold` (default: 1) bundles will be\noutput on the `fr` stream itself. The entry-specific bundles are diverted into\neach `'stream'` event's output. `opts.threshold` can be a number or a function\n`opts.threshold(row, groups)` where `row` is a \n[module-deps](https://github.com/substack/module-deps) object and `groups` is \nan array of bundles which depend on the row. If the threshold function returns \n`true`, that row and all its dependencies will go to the `common` bundle. If \nfalse, the row (but not its dependencies) will go to each bundle in `groups`.\nFor example:\n\n``` js\nfactor(files, {threshold: function(row, groups) {\n    if (/.*a\\.js$/.test(row.id)) return false;\n    if (/.*[z]\\.js$/.test(row.id)) return true;\n    return this._defaultThreshold(row, groups);\n}});\n```\n\n# events\n\n## fr.on('stream', function (stream) {})\n\nEach entry file emits a `'stream'` event containing all of the entry-specific\nrows that are only used by that entry file (when `opts.threshold === 1`, the\ndefault).\n\nThe entry file name is available as `stream.file`.\n\n## b.on('factor.pipeline', function (file, pipeline) {})\n\nEmits the full path to the entry file (`file`) and a [labeled-stream-splicer](https://npmjs.org/package/labeled-stream-splicer) (`pipeline`) for each entry file with these labels:\n\n* `'pack'` - [browser-pack](https://npmjs.org/package/browser-pack)\n* `'wrap'` - apply final wrapping\n\nYou can call `pipeline.get` with a label name to get a handle on a stream pipeline that you can `push()`, `unshift()`, or `splice()` to insert your own transform streams.\n\nEvent handlers must be attached *before* calling `b.plugin`.\n\n# install\n\nWith [npm](https://npmjs.org) do:\n\n```\nnpm install factor-bundle\n```\n\n# license\n\nMIT\n","publish_time":1412812730806,"_cnpm_publish_time":1412812730806,"dist-tags":{"latest":"2.5.0"}}