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');
// Define a module "a" that depends another module called "b". If | |
// that other module also uses this type of boilerplate, then | |
// in the browser, it will create a global .b that is used below. | |
// If you do not want to support the browser global path, then you | |
// can remove the `root` use and the passing `this` as the first arg to | |
// the top function. | |
(function(root, factory) { | |
if (typeof exports === 'object') { |
//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. |
var FakeAPI = (function(){ | |
var api = { | |
add: null, | |
addWithCallback: null | |
} | |
function makeMethod(method) { | |
return function() { | |
var context = this; | |
var args = arguments; |
//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); | |
}, |
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');
/*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'; |
//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' |
//Store this file at CarePassMe/Controllers/DefaultRouter.js | |
define(['backbone', '../Collections/Course', '../Views/CourseList', '../Collections/Page', '../Views/Pages'], | |
function (Backbone, Course, CourseList, Page, Pages) { | |
//The default router for the application. | |
//If you wanted to keep the globals for use outside of requirejs modules, | |
//note the assignment as part of the return. Otherwise, if the globals | |
are not needed just return Backbone.Router.extend()... |
// Filename: src/js/collections/store/ArticlesCollection.js | |
define([ | |
'require', | |
'underscore', | |
'backbone', | |
'models/store/ArticleModel' | |
], function (require, _, Backbone, ArticleModel) { | |
var ArticlesCollection = Backbone.Collection.extend({ | |
model: function () { |
//in test1.js | |
define({ | |
paths: {}, | |
deps: ['test/_', 'test/$', 'dep1', 'dep2'], | |
callback: function (_, $, dep1, dep2) { | |
//test dep1 and dep2 in here | |
} | |
}); | |
//in test2.js |