.. | ||
bench | ||
bin | ||
example | ||
node_modules | ||
test | ||
.npmignore | ||
.travis.yml | ||
buffer.js | ||
bundle.sh | ||
index.js | ||
LICENSE | ||
package.json | ||
readme.markdown |
insert-module-globals
insert implicit module globals
(__filename
, __dirname
, process
, global
, and Buffer
)
into a module bundle stream generated by
module-deps
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