{"id":13398777,"url":"https://github.com/umdjs/umd","last_synced_at":"2025-05-13T00:05:38.619Z","repository":{"id":37359476,"uuid":"2620608","full_name":"umdjs/umd","owner":"umdjs","description":"UMD (Universal Module Definition) patterns for JavaScript modules that work everywhere.","archived":false,"fork":false,"pushed_at":"2024-11-26T23:55:09.000Z","size":49,"stargazers_count":7436,"open_issues_count":44,"forks_count":429,"subscribers_count":194,"default_branch":"master","last_synced_at":"2025-05-13T00:05:32.794Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/umdjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-10-21T14:08:25.000Z","updated_at":"2025-05-09T18:41:31.000Z","dependencies_parsed_at":"2022-07-12T05:30:36.421Z","dependency_job_id":"c03784c3-0531-4a5a-8c35-03d64dae042f","html_url":"https://github.com/umdjs/umd","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umdjs%2Fumd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umdjs%2Fumd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umdjs%2Fumd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umdjs%2Fumd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/umdjs","download_url":"https://codeload.github.com/umdjs/umd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253843213,"owners_count":21972873,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T19:00:31.586Z","updated_at":"2025-05-13T00:05:38.594Z","avatar_url":"https://github.com/umdjs.png","language":"JavaScript","readme":"## UMD (Universal Module Definition)\n\n[![Build Status](https://travis-ci.org/umdjs/umd.svg)](https://travis-ci.org/umdjs/umd)\n\nThis 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.\n\nThe 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.\n\nA 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 \u003cs\u003edoes\u003c/s\u003e 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).\n\nYet, 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.\n\nIn 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.\n\n### Variations\n\n#### Regular Module\n\n* [amdWeb.js](https://github.com/umdjs/umd/blob/master/templates/amdWeb.js) -\n  Defines a module that works with AMD and browser globals. If you also want\n  to export a global even when AMD is in play (useful if you are loading other\n  scripts that still expect that global), use\n  [amdWebGlobal.js](https://github.com/umdjs/umd/blob/master/templates/amdWebGlobal.js).\n* [returnExports.js](https://github.com/umdjs/umd/blob/master/templates/returnExports.js) -\n  Defines a module that works in Node, AMD and browser globals. If you also want\n  to export a global even when AMD is in play (useful if you are loading other\n  scripts that still expect that global), use\n  [returnExportsGlobal.js](https://github.com/umdjs/umd/blob/master/templates/returnExportsGlobal.js).\n* [commonjsStrict.js](https://github.com/umdjs/umd/blob/master/templates/commonjsStrict.js) -\n  Defines a module that works with more CommonJS runtimes, and for modules that\n  will have a circular dependency. If you also want\n  to export a global even when AMD is in play (useful if you are loading other\n  scripts that still expect that global), use\n  [commonjsStrictGlobal.js](https://github.com/umdjs/umd/blob/master/templates/commonjsStrictGlobal.js)\n\n#### jQuery Plugin\n\n* [jqueryPlugin.js](https://github.com/umdjs/umd/blob/master/templates/jqueryPlugin.js) -\n  Defines a jQuery plugin that works with AMD and browser globals.\n\n#### AMD with simple Node/CommonJS adapter\n\nThese are useful for using AMD style while still making modules that can be\nused in Node and installed via npm without extra dependencies to set up the\nfull AMD API.\n\nThis approach does not allow the use of [AMD loader plugins](https://github.com/amdjs/amdjs-api/wiki/Loader-Plugins),\njust basic JS module dependencies. It also does not support the\n[callback-style require](https://github.com/amdjs/amdjs-api/wiki/require) that\nis usable in AMD.\n\n* [nodeAdapter.js](https://github.com/umdjs/umd/blob/master/templates/nodeAdapter.js) -\n  Best for when using AMD style but want it to work in Node without a helper library\n  that sets up AMD.\n* [commonjsAdapter.js](https://github.com/umdjs/umd/blob/master/templates/commonjsAdapter.js) -\n  Similar to nodeAdapter.js, but compatible with more CommonJS runtimes, and if\n  you want to define a circular dependency.\n\n### Tooling\n\n#### Build tools\n\n* [docpad-plugin-umd](https://github.com/docpad/docpad-plugin-umd) is a [DocPad](http://docpad.org) plugin for surrounding JavaScript code with UMD boilerplate\n* [grunt-umd](https://github.com/alexlawrence/grunt-umd) is a [Grunt](http://gruntjs.com) task for surrounding JavaScript code with UMD boilerplate\n* [gulp-umd](https://github.com/eduardolundgren/gulp-umd) is a [Gulp](http://gulpjs.com/) task for surrounding JavaScript code with UMD boilerplate\n* [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.\n* [generator-umd](https://github.com/ruyadorno/generator-umd) is an Yeoman Generator that creates a single module project with UMD boilerplate\n\n\n#### Testing\n\n* [Unit testing UMD with grunt-contrib-jasmine](http://stackoverflow.com/questions/16940548/grunt-test-for-umd)\n\n### Resources\n\n* [Browserify and the Universal Module Definition](http://dontkry.com/posts/code/browserify-and-the-universal-module-definition.html)\n\n### Todos\n\n* noConflict. Although with AMD loaders and build tools, it should be possible to get version specific bindings,\n  maybe show a version that has a noConflict option.\n* Variation with attaching some functionality to a $ impersonator. Although, it is\ntempting to say for that case, ask for 'jquery' as a dependency, and if the developer\nwants to use something different than the actual 'jquery', map that file to the 'jquery' name.\nThat is one of the strengths of module names, they can be mapped to different implementations.\n* Usage examples\n    * Further justifications for usage\n    * Gotchas/custom-tweaks we're aware of, but would rather not apply to the default UMD boilerplate\n\n### Influences\n\nThe 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).\n\nEarlier UMD variations were also of influence, ranging from Kit-Cambridge's\n[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).\n\n### License\n\nCopyright (c) the UMD contributors\n\nLicensed under the [MIT License](https://github.com/umdjs/umd/blob/master/LICENSE.md).\n","funding_links":[],"categories":["JavaScript","HarmonyOS","代码规范\u0026设计模式","API 📝","**Programming (learning)**"],"sub_categories":["Windows Manager","Usage","**Developer\\'s Tools**"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumdjs%2Fumd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fumdjs%2Fumd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumdjs%2Fumd/lists"}