nyc-bookstores/node_modules/browserify/node_modules/insert-module-globals
2013-05-27 13:45:59 -07:00
..
bench all da files 2013-05-27 13:45:59 -07:00
bin all da files 2013-05-27 13:45:59 -07:00
example all da files 2013-05-27 13:45:59 -07:00
node_modules all da files 2013-05-27 13:45:59 -07:00
test all da files 2013-05-27 13:45:59 -07:00
.npmignore all da files 2013-05-27 13:45:59 -07:00
.travis.yml all da files 2013-05-27 13:45:59 -07:00
buffer.js all da files 2013-05-27 13:45:59 -07:00
bundle.sh all da files 2013-05-27 13:45:59 -07:00
index.js all da files 2013-05-27 13:45:59 -07:00
LICENSE all da files 2013-05-27 13:45:59 -07:00
package.json all da files 2013-05-27 13:45:59 -07:00
readme.markdown all da files 2013-05-27 13:45:59 -07:00

insert-module-globals

insert implicit module globals (__filename, __dirname, process, global, and Buffer) into a module bundle stream generated by module-deps

build status

example

var mdeps = require('module-deps');
var bpack = require('browser-pack');
var insert = require('insert-module-globals');

var files = [ __dirname + '/files/main.js' ];
mdeps(files)
    .pipe(insert(files))
    .pipe(bpack({ raw: true }))
    .pipe(process.stdout)
;
$ node example/insert.js | node
in main.js: {"__filename":"/main.js","__dirname":"/"}
in foo/index.js: {"__filename":"/foo/index.js","__dirname":"/foo"}

or use the command-line scripts:

$ module-deps main.js | insert-module-globals main.js | browser-pack | node
in main.js: {"__filename":"/main.js","__dirname":"/"}
in foo/index.js: {"__filename":"/foo/index.js","__dirname":"/foo"}

methods

var insertGlobals = require('insert-module-globals')

var insert = insertGlobals(files, opts)

Insert globals for an array of entry files. The files array is used to rebase the __filename and __dirname names or you can pass in an opts.basedir explicitly.

You can pass in a custom opts.resolve(id, parent, cb) function. By default browser-resolve is used for the opts.resolve.

When opts.always is truthy, wrap every file with all the global variables without parsing. This is handy because parsing the scope can take a long time, so you can prioritize fast builds over saving bytes in the final output.

Return a through stream insert that expects input from the format written by module-deps. The insert stream will output data that can be fed into browser-pack.

usage

usage: insert-module-globals [files]

install

With npm, to get the library do:

npm install insert-module-globals

and to get the bin script do:

npm install -g insert-module-globals

license

MIT