component-as-module

0.3.0 • Public • Published

component-as-module

It allows you to require components from node programs.

Lookup algorithm is slightly different from component/builder.js in that it does not respect .paths field from component.json.

Examples

Require stand-alone component (with all dependencies in a ./components dir):

var component = require('component-as-module')
var min = component('/path-to/component-min')

Setup loader:

var boot = component('boot', function(loader) {
  // add lookup paths
  loader.addLookup('./components')
 
  // enable dev dependencies
  loader.development()
 
  // register node module as a component
  loader.register('foo', require)
})

Alternative way to require components is to create a special "require" function:

var req = component.createRequire(function(loader) {
  loader.addLookup('components')
})
 
var min = req('component-min')

This differs in that all loaded components are preserved between calls, so, for example, requiring component-min the second time is fast and you get the same instance.

Installation

with npm

npm install component-as-module

To run tests

npm install -d
npm test

Related

There is also component-npm-post-install script which can be used to make component package compatible with npm.

License

MIT

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i component-as-module

    Weekly Downloads

    1

    Version

    0.3.0

    License

    none

    Last publish

    Collaborators

    • eldar