Git Product home page Git Product logo

browser-pack's Introduction

browser-pack

pack node-style source files from a json stream into a browser bundle

browser support

build status

example

json input:

[
  {
    "id": "a1b5af78",
    "source": "console.log(require('./foo')(5))",
    "deps": { "./foo": "b8f69fa5" },
    "entry": true
  },
  {
    "id": "b8f69fa5",
    "source": "module.exports = function (n) { return n * 111 }",
    "deps": {}
  }
]

bundle script:

var pack = require('browser-pack')();
process.stdin.pipe(pack).pipe(process.stdout);
process.stdin.resume();

output:

$ browser-pack < input.json
(function(p,c,e){function r(n){if(!c[n]){c[n]={exports:{}};p[n][0](function(x){return r(p[n][1][x])},c[n],c[n].exports);}return c[n].exports}for(var i=0;i<e.length;i++)r(e[i]);return r})({"a1b5af78":[function(require,module,exports){console.log(require('./foo')(5))},{"./foo":"b8f69fa5"}],"b8f69fa5":[function(require,module,exports){module.exports = function (n) { return n * 111 }},{}]},{},["a1b5af78","b8f69fa5"])

methods

var pack = require('browser-pack');

pack(opts)

Return a through stream that takes a stream of json input and produces a stream of javascript output. This module does not export its internal require() function but you can prepend 'var require=' to the stream contents to get the require function. require() will return undefined when a module hasn't been defined to support splitting up modules across several bundles with custom fallback logic.

If opts.raw is given, the writable end of the stream will expect objects to be written to it instead of expecting a stream of json text it will need to parse.

Additionally, rows with a truthy entry may have an order field that determines the numeric index to execute the entries in.

You can specify a custom prelude with opts.prelude but you should really know what you're doing first. See the prelude.js file in this repo for the default prelude.

install

With npm, to get the library do:

npm install browser-pack

and to get the command-line tool do:

npm install -g browser-pack

license

MIT

browser-pack's People

Contributors

defunctzombie avatar dominictarr avatar esamattis avatar thlorenz avatar

Watchers

 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.