1.0.1 • Published 9 years ago
depx v1.0.1
depx
load project modules (internal dependencies) the simplest way in a node.js environment
usage
install
npm install depx --savein your boot file:
require('depx')(__dirname); // maps all .js and .coffee filesconfiguration 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 reqularrequireif 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
requireis 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_stuffas variable dep.rootanddepx.rootwill contain an absolute path to the dependency root directory (the resolved path todirinrequire('depx')(dir))