Module concatenation format:
JS module systems, whether commonjs/node, AMD or es harmony modules all allow specifying dependencies inline. Example from node:
var a = require('a'),
b = require('b');
//Set up the adapter config, so that any module asking | |
//for jquery gets an adapter module that has modified | |
//jquery before other modules can use it. | |
//Needs RequireJS 2.0+ to work correctly | |
//More info on map config: | |
//http://requirejs.org/docs/api.html#config-map | |
requirejs.config({ | |
map: { | |
'*': { | |
'jquery': 'jquery.adapter' |
requirejs.config({ | |
map: { | |
'*': { | |
'jquery': 'jquery-adapter' | |
}, | |
'jquery-adapter': { | |
'jquery': 'jquery' | |
} | |
}); |
if (someConditionIsTrueFromQueryString) { | |
require(['testmain'], function () { | |
require(['test'], function (test) { | |
}); | |
}); | |
} else { | |
require(['test'], function (test) { |
/*jslint regexp: true */ | |
/*global define, console, process */ | |
var connect = require( "connect" ), | |
crypto = require('crypto'), | |
fs = require('fs'), | |
path = require('path'), | |
buildDir = 'www-built', | |
pagesDir = 'www-ghpages'; |
Module concatenation format:
JS module systems, whether commonjs/node, AMD or es harmony modules all allow specifying dependencies inline. Example from node:
var a = require('a'),
b = require('b');
var requirejs = require('requirejs'), | |
foo = require('foo'); | |
requirejs.define('node/print', [], function () { | |
function print(msg) { | |
//Do whatever you want with the msg here. | |
//If you use node dependencies, can just require | |
//them outside of this closure. | |
foo(msg); | |
} |
//based on: | |
//https://github.com/lmorchard/kumascript/blob/master/lib/kumascript/templates.js | |
var q = require('q'); | |
var EJSTemplate = ks_utils.Class(BaseTemplate, { | |
initialize: function (options) { | |
this._super('initialize', arguments); | |
this.template = require('ejs').compile(this.options.source); | |
}, |
Attempt to list some possible standard AMD loader configuration values.
An AMD loader is not required to implement all of these configuration values, but if it does provide a capability that is satisfied by these configuration values, it should use these configuration values and structures.
String: Indicates the root used for ID-to-path resolutions. Relative paths are relative to the current working directory. In web browsers, the current working directory is the directory containing the web page running the script.
var FakeAPI = (function(){ | |
var api = { | |
add: null, | |
addWithCallback: null | |
} | |
function makeMethod(method) { | |
return function() { | |
var context = this; | |
var args = arguments; |
//Download jquery.js and place it in the build, do not use require-jquery.js | |
//in the build, since each of the build layers just needs almond and not the | |
//full require.js file. | |
//This file is run in nodejs to do the build: node build.js | |
//Load the requirejs optimizer | |
var requirejs = require('./r.js'); | |
//Set up basic config, include config that is | |
//common to all the requirejs.optimize() calls. |