depx
v1.0.1
Published
load project modules (internal dependencies) the simplest way in a node.js environment
Downloads
12
Readme
depx
load project modules (internal dependencies) the simplest way in a node.js environment
usage
install
npm install depx --save
in your boot file:
require('depx')(__dirname); // maps all .js and .coffee files
configuration option defaults
require('depx')(dir, {
forceUpdateRootDir: false,
extensions: ['js', 'coffee'],
exclude: []
});
from this point on (including all require()
-ed files)
depx('mySharedLib amazingHelper')
// ...
console.log(mySharedLib, 'is now available as a local variable');
console.log(amazingHelper, 'is available too');
notes
- it will not cache
node_modules/**/*
stuff, but it will fall back to reqularrequire
if it does not find a local includable - it requires only on demand by default. If you want to pull in a module that exposes globals or has to be run immediately, mark it with a star and call it like this:
depx('*immediateModule')
- syncronous mapping of local files when initialized: this is needed because
require
is syncronous itself, but it might add to the boot time a little if your project has many folders and files - it will expose
depx()
on the global scope (and the aliasdep()
too) - it will normalize dashes in the names of dependencies. E.g.:
dep('my-stuff')
will exposemy_stuff
as variable dep.root
anddepx.root
will contain an absolute path to the dependency root directory (the resolved path todir
inrequire('depx')(dir)
)