GitXplorerGitXplorer
d

node-define

public
3 stars
0 forks
1 issues

Commits

List of commits on branch master.
Unverified
771bbcf7b8166464c9d598a134730a16f6936bc9

0.1.1

committed 11 years ago
Unverified
d31af05a84209b570a7ba1809d56c22cd12d1851

Add example and tags

committed 11 years ago
Unverified
04b3b09e19dbb588aedc6625fe2e3b9b65734875

0.1.0

committed 11 years ago
Unverified
b55b03548ef1fe97d18e40d302c7f4616d15059b

Work on README

committed 11 years ago
Unverified
5e343501eeab84fcf958865bbf642261d5a0cb13

Only set `baseUrl` once, so that it can be overwritten

committed 11 years ago
Unverified
c1e589fe91ee909da95c3120c71fba63894d6a0e

Export requirejs and configuration function

committed 11 years ago

README

The README file for this repository.

node-define

Makes AMD modules require’able in node by adding a global define function that delegates to RequireJS. The module configures RequireJS to use process.cwd() as baseUrl once and the module-local node require for every call to define.

Usage

  • Install with npm: npm install node-define
  • Require the module: require('node-define')

Note: node-define deliberately does not expose define.amd. This way, modules in the UMD format will take the “node route” instead of using define. Named modules work better this way.

Further Configuration

The module exposes RequireJS as requirejs property, and a config method that takes the same arguments as requirejs.config. Note that passing a nodeRequire option will be overwritten by node-define itself, as it always passes the module-local require to RequireJS.

Example: mocha tests

For AMD-based projects with a mocha test suite, this module can help with executing the tests in node.js:

mocha -r node-define

Letting mocha require the module will create a synchronous global define function that can load tests and code before mocha starts running, avoiding the problem that mocha does not pick up test suites when code is pulled in asynchronously.

For further configuration, a simple setup module can be created that pulls in node-require and provides further configuration. Simply pass that module to mocha with the -r switch.