公告:请大家务必使用 HTTPS 方式访问 Git@OSC 点击查看详情

pack node-style source files from a json stream into a browser bundle —— 查看更多

8 commits
d8ed1202812 minicoder 最后提交于 2013-09-09 16:12
File_dir example 2013-09-06 14:42 minicoder rebrowser-pack framework code init
File_dir test 2013-09-06 14:42 minicoder rebrowser-pack framework code init
File_txt .npmignore 2013-09-06 minicoder rebrowser-pack framework code init
File_txt .travis.yml 2013-09-06 minicoder rebrowser-pack framework code init
File_txt LICENSE 2013-09-06 minicoder rebrowser-pack framework code init
File_txt README.md 2013-09-06 minicoder readme update
File_txt cmd.js 2013-09-06 minicoder rebrowser-pack framework code init
File_txt finale-master.js 2013-09-06 minicoder rebrowser-pack framework code init
File_txt finale-slave.js 2013-09-06 minicoder rebrowser-pack framework code init
File_txt index.js 2013-09-06 minicoder rebrowser-pack framework code init
File_txt package.json 2013-09-09 minicoder package.json update
File_txt prelude.js 2013-09-06 minicoder rebrowser-pack framework code init
README.md

rebrowser-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('rebrowser-pack')();
process.stdin.pipe(pack).pipe(process.stdout);
process.stdin.resume();

output:

$ rebrowser-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('rebrowser-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.

install

With npm, to get the library do:

npm install rebrowser-pack

and to get the command-line tool do:

npm install -g rebrowser-pack

license

MIT