Coder Social home page Coder Social logo

bundle-collapser's Introduction

bundle-collapser

convert bundle paths to IDs to save bytes in browserify bundles

build status

example

var collapse = require('bundle-collapser');
var fs = require('fs');

var src = fs.readFileSync(__dirname + '/bundle.js', 'utf8');
collapse(src).pipe(process.stdout);

The input bundle has require(string) paths in it:

(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<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
module.exports = function (n) { return n * 5 }

},{}],2:[function(require,module,exports){
var bar = require('./bar.js');

module.exports = function (n) { return bar(n+1) }

},{"./bar.js":1}],3:[function(require,module,exports){
var foo = require('./foo.js');
var bar = require('./bar.js');

console.log(foo(5) * bar(2));

},{"./bar.js":1,"./foo.js":2}]},{},[3]);

but the output just has the integers:

(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<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
module.exports = function (n) { return n * 5 }


},{}],2:[function(require,module,exports){
var bar = require(1);

module.exports = function (n) { return bar(n+1) }


},{}],3:[function(require,module,exports){
var foo = require(2);
var bar = require(1);

console.log(foo(5) * bar(2));
},{}]},{},[3]);

usage

There is also a command-line program included in this distribution:

usage: bundle-collapser {FILE | -} {OPTIONS}

  Collapse a browser-pack/browserify bundle from STDIN or a FILE.

OPTIONS:

  -h --help  Show this message.

methods

var collapse = require('bundle-collapser')

var stream = collapse(src)

Return a readable stream of output from browser-pack with the input source string src converted to have its require() calls collapsed down to the dependency targets in the "deps" fields from the unpacking.

install

With npm, to get the library do:

npm install bundle-collapser

and to get the command-line program do:

npm install -g bundle-collapser

license

MIT

bundle-collapser's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.