├── .gitignore ├── .travis.yml ├── CHANGES ├── LICENSE.md ├── README.md ├── package.json └── templates ├── amdWeb.js ├── amdWebGlobal.js ├── commonjsAdapter.js ├── commonjsStrict.js ├── commonjsStrictGlobal.js ├── jqueryPlugin.js ├── nodeAdapter.js ├── returnExports.js └── returnExportsGlobal.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/node 2 | 3 | ### Node ### 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | 9 | # Runtime data 10 | pids 11 | *.pid 12 | *.seed 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directory 30 | # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git 31 | node_modules 32 | 33 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "stable" 4 | sudo: false 5 | -------------------------------------------------------------------------------- /CHANGES: -------------------------------------------------------------------------------- 1 | 2 | v2.0.0 3 | 4 | * jQuery is now provided by only one template. This template normalizes how 5 | modules built with it are used in CommonJS environments: 6 | 7 | require('./myJqueryPlugin')(window, [jQuery]); 8 | 9 | 10 | Providing window is mandated. This is because jQuery upstream, 11 | 12 | 1. Sometimes returns a factory, and only sometimes. 13 | 2. We *always* have access to window. 14 | 3. It makes the use of window explicit. 15 | 4. If jQuery ever provides access to the factory we are forward-compatable. 16 | 17 | For more information on this, read 18 | 19 | * http://stackoverflow.com/q/33404108/124486 20 | * https://github.com/umdjs/umd/issues/68 21 | 22 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 the [UMD contributors](https://github.com/umdjs/umd/graphs/contributors). 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## UMD (Universal Module Definition) 2 | 3 | [![Build Status](https://travis-ci.org/umdjs/umd.svg)](https://travis-ci.org/umdjs/umd) 4 | 5 | This repository formalizes the design and implementation of the Universal Module Definition (UMD) API for JavaScript modules. These are modules which are capable of working everywhere, be it in the client, on the server or elsewhere. 6 | 7 | The UMD pattern typically attempts to offer compatibility with the most popular script loaders of the day (e.g RequireJS amongst others). The repository aims to formalize the *definition* of *universal modules*. It does not provide a *universal definition*. The standard was written at the time because everyone defined their universal modules differently - there were some common approaches, with varying support for different environments, but nothing really established. 8 | 9 | A universal module, as already noted, works in multiple environments. Before universal modules, libraries would distribute separate files for the different environments, e.g. `library.amd.js`, `library.common.js` and `library.global.js`. This was a hassle for maintainers, since it required the usage of a build tool (which JavaScript does did generally not need) and extra documentation. So the aim was to define a universal module, a single file, which was all that was needed for the author to write and distribute and for the user to (down)load. Notice this was before package managers and repositories were common (or: when they started to become more popular, and you had to change your library into a module to support them). 10 | 11 | Yet, there were still variations. Modules written for web browsers did not need to consider supporting the commonjs format, as they wouldn't work in Node.JS anyway. Modules that had no dependencies wouldn't need a UMD pattern that supported `require`. Modules that did not use circular dependencies wouldn't need a pattern that supports a mutable `exports` object. You can find the explanation of these differences, and their trade-offs, in the comments documenting the patterns below. A library author can read through them and pick the right one for their supported environments. 12 | 13 | In many cases, UMD uses [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) as a base, with special-casing added to handle [CommonJS](http://wiki.commonjs.org/wiki/CommonJS) compatibility. 14 | 15 | ### Variations 16 | 17 | #### Regular Module 18 | 19 | * [amdWeb.js](https://github.com/umdjs/umd/blob/master/templates/amdWeb.js) - 20 | Defines a module that works with AMD and browser globals. If you also want 21 | to export a global even when AMD is in play (useful if you are loading other 22 | scripts that still expect that global), use 23 | [amdWebGlobal.js](https://github.com/umdjs/umd/blob/master/templates/amdWebGlobal.js). 24 | * [returnExports.js](https://github.com/umdjs/umd/blob/master/templates/returnExports.js) - 25 | Defines a module that works in Node, AMD and browser globals. If you also want 26 | to export a global even when AMD is in play (useful if you are loading other 27 | scripts that still expect that global), use 28 | [returnExportsGlobal.js](https://github.com/umdjs/umd/blob/master/templates/returnExportsGlobal.js). 29 | * [commonjsStrict.js](https://github.com/umdjs/umd/blob/master/templates/commonjsStrict.js) - 30 | Defines a module that works with more CommonJS runtimes, and for modules that 31 | will have a circular dependency. If you also want 32 | to export a global even when AMD is in play (useful if you are loading other 33 | scripts that still expect that global), use 34 | [commonjsStrictGlobal.js](https://github.com/umdjs/umd/blob/master/templates/commonjsStrictGlobal.js) 35 | 36 | #### jQuery Plugin 37 | 38 | * [jqueryPlugin.js](https://github.com/umdjs/umd/blob/master/templates/jqueryPlugin.js) - 39 | Defines a jQuery plugin that works with AMD and browser globals. 40 | 41 | #### AMD with simple Node/CommonJS adapter 42 | 43 | These are useful for using AMD style while still making modules that can be 44 | used in Node and installed via npm without extra dependencies to set up the 45 | full AMD API. 46 | 47 | This approach does not allow the use of [AMD loader plugins](https://github.com/amdjs/amdjs-api/wiki/Loader-Plugins), 48 | just basic JS module dependencies. It also does not support the 49 | [callback-style require](https://github.com/amdjs/amdjs-api/wiki/require) that 50 | is usable in AMD. 51 | 52 | * [nodeAdapter.js](https://github.com/umdjs/umd/blob/master/templates/nodeAdapter.js) - 53 | Best for when using AMD style but want it to work in Node without a helper library 54 | that sets up AMD. 55 | * [commonjsAdapter.js](https://github.com/umdjs/umd/blob/master/templates/commonjsAdapter.js) - 56 | Similar to nodeAdapter.js, but compatible with more CommonJS runtimes, and if 57 | you want to define a circular dependency. 58 | 59 | ### Tooling 60 | 61 | #### Build tools 62 | 63 | * [docpad-plugin-umd](https://github.com/docpad/docpad-plugin-umd) is a [DocPad](http://docpad.org) plugin for surrounding JavaScript code with UMD boilerplate 64 | * [grunt-umd](https://github.com/alexlawrence/grunt-umd) is a [Grunt](http://gruntjs.com) task for surrounding JavaScript code with UMD boilerplate 65 | * [gulp-umd](https://github.com/eduardolundgren/gulp-umd) is a [Gulp](http://gulpjs.com/) task for surrounding JavaScript code with UMD boilerplate 66 | * [grunt-urequire](https://github.com/aearly/grunt-urequire) is a Grunt wrapper for [uRequire](https://github.com/anodynos/uRequire) a conversion tool for universal JavaScript modules. 67 | * [generator-umd](https://github.com/ruyadorno/generator-umd) is an Yeoman Generator that creates a single module project with UMD boilerplate 68 | 69 | 70 | #### Testing 71 | 72 | * [Unit testing UMD with grunt-contrib-jasmine](http://stackoverflow.com/questions/16940548/grunt-test-for-umd) 73 | 74 | ### Resources 75 | 76 | * [Browserify and the Universal Module Definition](http://dontkry.com/posts/code/browserify-and-the-universal-module-definition.html) 77 | 78 | ### Todos 79 | 80 | * noConflict. Although with AMD loaders and build tools, it should be possible to get version specific bindings, 81 | maybe show a version that has a noConflict option. 82 | * Variation with attaching some functionality to a $ impersonator. Although, it is 83 | tempting to say for that case, ask for 'jquery' as a dependency, and if the developer 84 | wants to use something different than the actual 'jquery', map that file to the 'jquery' name. 85 | That is one of the strengths of module names, they can be mapped to different implementations. 86 | * Usage examples 87 | * Further justifications for usage 88 | * Gotchas/custom-tweaks we're aware of, but would rather not apply to the default UMD boilerplate 89 | 90 | ### Influences 91 | 92 | The basic pattern for the UMD variations in this repository was derived from the approach [@kriskowal](https://github.com/kriskowal) used for the [Q promise library](https://github.com/kriskowal/q). 93 | 94 | Earlier UMD variations were also of influence, ranging from Kit-Cambridge's 95 | [UMD](https://gist.github.com/1251221), through to [patterns](https://github.com/addyosmani/jquery-plugin-patterns/issues/1) discussed by Addy Osmani, Thomas Davis and Ryan Florence and most recently the UMD patterns proposed by [James Burke](https://gist.github.com/1262861). 96 | 97 | ### License 98 | 99 | Copyright (c) the UMD contributors 100 | 101 | Licensed under the [MIT License](https://github.com/umdjs/umd/blob/master/LICENSE.md). 102 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "umdjs", 3 | "version": "2.0.0", 4 | "description": "UMD (Universal Module Definition)", 5 | "main": "amdWeb.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/umdjs/umd" 9 | }, 10 | "keywords": [ 11 | "umd", 12 | "umdjs", 13 | "universal", 14 | "module", 15 | "definition" 16 | ], 17 | "author": "The UMD Authors", 18 | "license": "MIT", 19 | "bugs": { 20 | "url": "https://github.com/umdjs/umd/issues" 21 | }, 22 | "homepage": "https://github.com/umdjs/umd", 23 | "scripts": { 24 | "test": "npm run lint", 25 | "lint": "jshint templates/*.js" 26 | }, 27 | "devDependencies": { 28 | "jshint": "^2.8.0" 29 | }, 30 | "dependencies": { 31 | "jquery": "^2.1.4" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /templates/amdWeb.js: -------------------------------------------------------------------------------- 1 | // Uses AMD or browser globals to create a module. 2 | 3 | // If you want something that will also work in Node, see returnExports.js 4 | // If you want to support other stricter CommonJS environments, 5 | // or if you need to create a circular dependency, see commonJsStrict.js 6 | 7 | // Defines a module "amdWeb" that depends on another module called "b". 8 | // Note that the name of the module is implied by the file name. It is best 9 | // if the file name and the exported global have matching names. 10 | 11 | // If the 'b' module also uses this type of boilerplate, then 12 | // in the browser, it will create a global .b that is used below. 13 | 14 | // If you do not want to support the browser global path, then you 15 | // can remove the `root` use and the passing of `this` as the first arg to 16 | // the top function. 17 | 18 | (function (root, factory) { 19 | if (typeof define === 'function' && define.amd) { 20 | // AMD. Register as an anonymous module. 21 | define(['b'], factory); 22 | } else { 23 | // Browser globals 24 | root.amdWeb = factory(root.b); 25 | } 26 | }(typeof self !== 'undefined' ? self : this, function (b) { 27 | // Use b in some fashion. 28 | 29 | // Just return a value to define the module export. 30 | // This example returns an object, but the module 31 | // can return a function as the exported value. 32 | return {}; 33 | })); 34 | -------------------------------------------------------------------------------- /templates/amdWebGlobal.js: -------------------------------------------------------------------------------- 1 | // Uses AMD or browser globals to create a module. This example creates a 2 | // global even when AMD is used. This is useful if you have some scripts 3 | // that are loaded by an AMD loader, but they still want access to globals. 4 | // If you do not need to export a global for the AMD case, see amdWeb.js. 5 | 6 | // If you want something that will also work in Node, and still export a 7 | // global in the AMD case, see returnExportsGlobal.js 8 | // If you want to support other stricter CommonJS environments, 9 | // or if you need to create a circular dependency, see commonJsStrictGlobal.js 10 | 11 | // Defines a module "amdWebGlobal" that depends another module called "b". 12 | // Note that the name of the module is implied by the file name. It is best 13 | // if the file name and the exported global have matching names. 14 | 15 | // If the 'b' module also uses this type of boilerplate, then 16 | // in the browser, it will create a global .b that is used below. 17 | 18 | (function (root, factory) { 19 | if (typeof define === 'function' && define.amd) { 20 | // AMD. Register as an anonymous module. 21 | define(['b'], function (b) { 22 | // Also create a global in case some scripts 23 | // that are loaded still are looking for 24 | // a global even when an AMD loader is in use. 25 | return (root.amdWebGlobal = factory(b)); 26 | }); 27 | } else { 28 | // Browser globals 29 | root.amdWebGlobal = factory(root.b); 30 | } 31 | }(typeof self !== 'undefined' ? self : this, function (b) { 32 | // Use b in some fashion. 33 | 34 | // Just return a value to define the module export. 35 | // This example returns an object, but the module 36 | // can return a function as the exported value. 37 | return {}; 38 | })); 39 | -------------------------------------------------------------------------------- /templates/commonjsAdapter.js: -------------------------------------------------------------------------------- 1 | // Defines a module that works in CommonJS and AMD. 2 | 3 | // This version can be used as common boilerplate for a library module 4 | // that you only want to expose to CommonJS and AMD loaders. It will not work 5 | // well for defining browser globals. 6 | 7 | // If you only want to target Node and AMD or a CommonJS environment that 8 | // supports assignment to module.exports and you are not defining a module 9 | // that has a circular dependency, see nodeAdapter.js 10 | 11 | // Help Node out by setting up define. 12 | if (typeof exports === 'object' && typeof exports.nodeName !== 'string' && typeof define !== 'function') { 13 | var define = function (factory) { 14 | factory(require, exports, module); 15 | }; 16 | } 17 | 18 | define(function (require, exports, module) { 19 | var b = require('b'); 20 | 21 | // Only attach properties to the exports object to define 22 | // the module's properties. 23 | exports.action = function () {}; 24 | }); 25 | -------------------------------------------------------------------------------- /templates/commonjsStrict.js: -------------------------------------------------------------------------------- 1 | // Uses CommonJS, AMD or browser globals to create a module. 2 | 3 | // If you just want to support Node, or other CommonJS-like environments that 4 | // support module.exports, and you are not creating a module that has a 5 | // circular dependency, then see returnExports.js instead. It will allow 6 | // you to export a function as the module value. 7 | 8 | // Defines a module "commonJsStrict" that depends another module called "b". 9 | // Note that the name of the module is implied by the file name. It is best 10 | // if the file name and the exported global have matching names. 11 | 12 | // If the 'b' module also uses this type of boilerplate, then 13 | // in the browser, it will create a global .b that is used below. 14 | 15 | // If you do not want to support the browser global path, then you 16 | // can remove the `root` use and the passing `this` as the first arg to 17 | // the top function. 18 | 19 | (function (root, factory) { 20 | if (typeof define === 'function' && define.amd) { 21 | // AMD. Register as an anonymous module. 22 | define(['exports', 'b'], factory); 23 | } else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') { 24 | // CommonJS 25 | factory(exports, require('b')); 26 | } else { 27 | // Browser globals 28 | factory((root.commonJsStrict = {}), root.b); 29 | } 30 | }(typeof self !== 'undefined' ? self : this, function (exports, b) { 31 | // Use b in some fashion. 32 | 33 | // attach properties to the exports object to define 34 | // the exported module properties. 35 | exports.action = function () {}; 36 | })); 37 | -------------------------------------------------------------------------------- /templates/commonjsStrictGlobal.js: -------------------------------------------------------------------------------- 1 | // Uses CommonJS, AMD or browser globals to create a module. This example 2 | // creates a global even when AMD is used. This is useful if you have some 3 | // scripts that are loaded by an AMD loader, but they still want access to 4 | // globals. If you do not need to export a global for the AMD case, see 5 | // commonjsStrict.js. 6 | 7 | // If you just want to support Node, or other CommonJS-like environments that 8 | // support module.exports, and you are not creating a module that has a 9 | // circular dependency, then see returnExportsGlobal.js instead. It will allow 10 | // you to export a function as the module value. 11 | 12 | // Defines a module "commonJsStrictGlobal" that depends another module called 13 | // "b". Note that the name of the module is implied by the file name. It is 14 | // best if the file name and the exported global have matching names. 15 | 16 | // If the 'b' module also uses this type of boilerplate, then 17 | // in the browser, it will create a global .b that is used below. 18 | 19 | (function (root, factory) { 20 | if (typeof define === 'function' && define.amd) { 21 | // AMD. Register as an anonymous module. 22 | define(['exports', 'b'], function (exports, b) { 23 | factory((root.commonJsStrictGlobal = exports), b); 24 | }); 25 | } else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') { 26 | // CommonJS 27 | factory(exports, require('b')); 28 | } else { 29 | // Browser globals 30 | factory((root.commonJsStrictGlobal = {}), root.b); 31 | } 32 | }(typeof self !== 'undefined' ? self : this, function (exports, b) { 33 | // Use b in some fashion. 34 | 35 | // attach properties to the exports object to define 36 | // the exported module properties. 37 | exports.action = function () {}; 38 | })); 39 | -------------------------------------------------------------------------------- /templates/jqueryPlugin.js: -------------------------------------------------------------------------------- 1 | // Uses CommonJS, AMD or browser globals to create a jQuery plugin. 2 | 3 | (function (factory) { 4 | if (typeof define === 'function' && define.amd) { 5 | // AMD. Register as an anonymous module. 6 | define(['jquery'], factory); 7 | } else if (typeof module === 'object' && module.exports) { 8 | // Node/CommonJS 9 | module.exports = function( root, jQuery ) { 10 | if ( jQuery === undefined ) { 11 | // require('jQuery') returns a factory that requires window to 12 | // build a jQuery instance, we normalize how we use modules 13 | // that require this pattern but the window provided is a noop 14 | // if it's defined (how jquery works) 15 | if ( typeof window !== 'undefined' ) { 16 | jQuery = require('jquery'); 17 | } 18 | else { 19 | jQuery = require('jquery')(root); 20 | } 21 | } 22 | factory(jQuery); 23 | return jQuery; 24 | }; 25 | } else { 26 | // Browser globals 27 | factory(jQuery); 28 | } 29 | }(function ($) { 30 | $.fn.jqueryPlugin = function () { return true; }; 31 | })); 32 | -------------------------------------------------------------------------------- /templates/nodeAdapter.js: -------------------------------------------------------------------------------- 1 | // Defines a module that works in Node and AMD. 2 | 3 | // This version can be used as common boilerplate for a library module 4 | // that you only want to expose to Node and AMD loaders. It will not work 5 | // well for defining browser globals. 6 | 7 | // If you need a version of this file that works CommonJS-like environments 8 | // that do not support module.exports or if you want to define a module 9 | // with a circular dependency, see commonjsAdapter.js 10 | 11 | (function(define) { 12 | 13 | define(function (require, exports, module) { 14 | var b = require('b'); 15 | 16 | return function () {}; 17 | }); 18 | 19 | }( // Help Node out by setting up define. 20 | typeof module === 'object' && module.exports && typeof define !== 'function' ? 21 | function (factory) { module.exports = factory(require, exports, module); } : 22 | define 23 | )); 24 | 25 | -------------------------------------------------------------------------------- /templates/returnExports.js: -------------------------------------------------------------------------------- 1 | // Uses Node, AMD or browser globals to create a module. 2 | 3 | // If you want something that will work in other stricter CommonJS environments, 4 | // or if you need to create a circular dependency, see commonJsStrict.js 5 | 6 | // Defines a module "returnExports" that depends another module called "b". 7 | // Note that the name of the module is implied by the file name. It is best 8 | // if the file name and the exported global have matching names. 9 | 10 | // If the 'b' module also uses this type of boilerplate, then 11 | // in the browser, it will create a global .b that is used below. 12 | 13 | // If you do not want to support the browser global path, then you 14 | // can remove the `root` use and the passing `this` as the first arg to 15 | // the top function. 16 | 17 | (function (root, factory) { 18 | if (typeof define === 'function' && define.amd) { 19 | // AMD. Register as an anonymous module. 20 | define(['b'], factory); 21 | } else if (typeof module === 'object' && module.exports) { 22 | // Node. Does not work with strict CommonJS, but 23 | // only CommonJS-like environments that support module.exports, 24 | // like Node. 25 | module.exports = factory(require('b')); 26 | } else { 27 | // Browser globals (root is window) 28 | root.returnExports = factory(root.b); 29 | } 30 | }(typeof self !== 'undefined' ? self : this, function (b) { 31 | // Use b in some fashion. 32 | 33 | // Just return a value to define the module export. 34 | // This example returns an object, but the module 35 | // can return a function as the exported value. 36 | return {}; 37 | })); 38 | 39 | 40 | // if the module has no dependencies, the above pattern can be simplified to 41 | (function (root, factory) { 42 | if (typeof define === 'function' && define.amd) { 43 | // AMD. Register as an anonymous module. 44 | define([], factory); 45 | } else if (typeof module === 'object' && module.exports) { 46 | // Node. Does not work with strict CommonJS, but 47 | // only CommonJS-like environments that support module.exports, 48 | // like Node. 49 | module.exports = factory(); 50 | } else { 51 | // Browser globals (root is window) 52 | root.returnExports = factory(); 53 | } 54 | }(typeof self !== 'undefined' ? self : this, function () { 55 | 56 | // Just return a value to define the module export. 57 | // This example returns an object, but the module 58 | // can return a function as the exported value. 59 | return {}; 60 | })); 61 | -------------------------------------------------------------------------------- /templates/returnExportsGlobal.js: -------------------------------------------------------------------------------- 1 | // Uses Node, AMD or browser globals to create a module. This example creates 2 | // a global even when AMD is used. This is useful if you have some scripts 3 | // that are loaded by an AMD loader, but they still want access to globals. 4 | // If you do not need to export a global for the AMD case, 5 | // see returnExports.js. 6 | 7 | // If you want something that will work in other stricter CommonJS environments, 8 | // or if you need to create a circular dependency, see commonJsStrictGlobal.js 9 | 10 | // Defines a module "returnExportsGlobal" that depends another module called 11 | // "b". Note that the name of the module is implied by the file name. It is 12 | // best if the file name and the exported global have matching names. 13 | 14 | // If the 'b' module also uses this type of boilerplate, then 15 | // in the browser, it will create a global .b that is used below. 16 | 17 | (function (root, factory) { 18 | if (typeof define === 'function' && define.amd) { 19 | // AMD. Register as an anonymous module. 20 | define(['b'], function (b) { 21 | return (root.returnExportsGlobal = factory(b)); 22 | }); 23 | } else if (typeof module === 'object' && module.exports) { 24 | // Node. Does not work with strict CommonJS, but 25 | // only CommonJS-like environments that support module.exports, 26 | // like Node. 27 | module.exports = factory(require('b')); 28 | } else { 29 | // Browser globals 30 | root.returnExportsGlobal = factory(root.b); 31 | } 32 | }(typeof self !== 'undefined' ? self : this, function (b) { 33 | // Use b in some fashion. 34 | 35 | // Just return a value to define the module export. 36 | // This example returns an object, but the module 37 | // can return a function as the exported value. 38 | return {}; 39 | })); 40 | --------------------------------------------------------------------------------