Neuron is A Full Feature CommonJS Module Manager, Dependency Graph Handler and Loader for Browsers
First of all, neuron is not designed for human developers to use directly. Most usually, it works together with cortex.
Neuron is a full feature CommonJS module loader which makes your node-style modules run in browsers.
require.resolve()for browsers which is similar to node.js.
You could remove all those annoying and noisy things out of your mind, and, just focus on the origin and code your web modules like node.js.
Neuron is designed to run in the background without your concern, UNLIKE RequireJS and many other loaders.
We're trying to return to the origin of commonjs. There should be only ONE standard, that is, Module/1.0.
var neuron = require'neuronjs';neuronversion; // 6.0.0neuroncontentcontent; // The file content of neuron.js;
String the version of neuron for browsers, not the version of npm module
Writes the content of neuron.js to the
Bufferthe buffer of the content of neuron.js
Gets the content of neuron.js
Frequent configurations, for more, just see
Configuration Hierarchies section.
For the example above:
'firstname.lastname@example.org' will be located at
To require modules. See CommonJS Module/1.0
function(exports)callback must be passed, or
require.asyncwill do nothing.
Asynchronously loads a module by
id, and then passes the module
You should always pass the
callback parameter because neuron can not make sure the exact time when a module is loaded asynchronously.
It is NOT a good practice if the logic of your code relies on the result of the
require.async()d module without a callback.
Stringthe relative path to be resolved according to the current module.
Returns the resolved absolute path of the resource.
path is not a relative path.
path is even outside the current package.
With cortex, you might NEVER use this method.
defineidentifier dependencies factory options;
facadeidentifier;facademod: identifierdata: data;
facade loads a module. If the
module.exports has a method named
facade method will run the
We call this kind of modules as facade modules
module name with version, seperated with
'@'. For example:
data is defined, data will be passed as the parameter of the
Neuron CORE supplies no high-level APIs, which means that neuron core only cares about module dependencies and module wrapping while will do nothing about things such as fetching modules from remote server and injecting them into the current document, and never cares about where a specific module should come from.
You could do all these things in your will (by write your own
lib/load.js and adjust
Gruntfile.js). Nevertheless, neuron have a basic configuration file which located at
CommonJS module path, like
NODE_PATH, default to 'the root directory of neuronjs'.
Pay attension that
path will not be resolved to absolute url. So if you don't want a relative
path, don't forget
To tell neuron loader that those modules are already loaded, and prevent duplicate loading.
String, we can separate different ids with
neuronconfigloaded: 'email@example.com' 'firstname.lastname@example.org';
The arithmetics to generate the graph is complicated and hard to describe, see https://github.com/kaelzhang/neuron/blob/master/doc/graph.md for details (Too Long; Don't Read)
|beforeready||when the module is needed by others|
|beforeload||before being downloaded|
|load||when the module is downloaded|
|ready||when the module is ready to be |
neuronon'ready'console.log'module "' + id + '" is ready to be `require()`d';;