Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

browserify/browser-pack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

168 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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:

varpack=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

varpack=require('browser-pack');

pack(opts)

Return a through stream that takes a stream of json input and produces a streamof javascript output. This module does not export its internalrequire()function but you can prepend'var require=' to the stream contents to get therequire function.require() will returnundefined when a module hasn't beendefined to support splitting up modules across several bundles with customfallback logic.

Ifopts.raw is given, the writable end of the stream will expect objects to bewritten to it instead of expecting a stream of json text it will need to parse.

Ifopts.sourceMapPrefix is given and source maps are computed, theopts.sourceMapPrefix string will be used instead of//#.

Ifopts.sourceRoot is given and source maps are computed, the root for theoutput source map will be defined. (default is no root)

Additionally, rows with a truthyentry may have anorder field thatdetermines the numeric index to execute the entries in.

You can specify a custom prelude withopts.prelude but you should really knowwhat you're doing first. See theprelude.js file in this repo for the defaultprelude. If you specify a custom prelude, you must also specify a validopts.preludePath to the prelude source file for sourcemaps to work.

opts.standalone external string name to use for umd

opts.standaloneModule sets the internal module name to export for standalone

opts.hasExports whether the bundle should includerequire= (or theopts.externalRequireName) so thatrequire() is available outside the bundle

install

Withnpm, to get the library do:

npm install browser-pack

and to get the command-line tool do:

npm install -g browser-pack

input objects

Input objects are written to browser-pack usingbpack.write(row). browser-packuses these properties:

  • id - A unique ID for this module.
  • deps - An object mappingrequire() argument strings to dependency rowIDs, used for resolution at runtime.
  • entry - When true, this module will be executed when the bundle loads.Otherwise, it will only be executed once some other modulerequire()s it.
  • order - Whenrow.entry is true, this number indicates the order in whichdifferent entry modules are executed.
  • source - The contents of the module.
  • nomap - When true, a source map is not generated for this module.
  • sourceFile - The file name to use for this module in the source map.

license

MIT

About

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

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors19


[8]ページ先頭

©2009-2026 Movatter.jp