{"id":30107047,"url":"https://github.com/benignware/grunt-amd-shim","last_synced_at":"2025-08-10T01:33:01.159Z","repository":{"id":17252799,"uuid":"20022252","full_name":"benignware/grunt-amd-shim","owner":"benignware","description":"Creates a define wrapper around javascript libraries to support anonymous amd loading","archived":false,"fork":false,"pushed_at":"2016-02-20T06:32:23.000Z","size":332,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-29T05:14:09.728Z","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/benignware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-21T13:31:41.000Z","updated_at":"2014-06-22T15:28:38.000Z","dependencies_parsed_at":"2022-09-26T21:20:42.076Z","dependency_job_id":null,"html_url":"https://github.com/benignware/grunt-amd-shim","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/benignware/grunt-amd-shim","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benignware%2Fgrunt-amd-shim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benignware%2Fgrunt-amd-shim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benignware%2Fgrunt-amd-shim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benignware%2Fgrunt-amd-shim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benignware","download_url":"https://codeload.github.com/benignware/grunt-amd-shim/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benignware%2Fgrunt-amd-shim/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269663320,"owners_count":24455797,"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","status":"online","status_checked_at":"2025-08-09T02:00:10.424Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-08-10T01:32:01.843Z","updated_at":"2025-08-10T01:33:01.104Z","avatar_url":"https://github.com/benignware.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# grunt-amd-shim\n\n\u003e Creates a define wrapper around javascript libraries to support anonymous amd loading\n\n## About\nThis grunt plugin provides a build task for making javascript libraries that do not include the define pattern compatible with amd loaders like requirejs by wrapping the code in an define call. \n\nAlso, most of the javascript libraries expose one or more global variables to the global window scope. This can lead to version conflicts when the embedding document also requires those modules.\nThe amdshim task anonymizes the module by saving and restoring previously set globals and exporting the reference loaded by amd. \n\n\n## Getting Started\nThis plugin requires Grunt `~0.4.5`\n\nIf you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:\n\n```shell\nnpm install grunt-amd-shim --save-dev\n```\n\nOnce the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:\n\n```js\ngrunt.loadNpmTasks('grunt-amd-shim');\n```\n\n## The \"amd_shim\" task\n\n### Overview\nIn your project's Gruntfile, add a section named `amd_shim` to the data object passed into `grunt.initConfig()`.\n\n```js\ngrunt.initConfig({\n  amd_shim: {\n    options: {\n      // Task-specific options go here.\n    },\n    your_target: {\n      // Target-specific file lists and/or options go here.\n    },\n  },\n});\n```\n\n### Options\n\n#### options.exports\nType: `String`\nDefault value: `''`\n\nThe global reference to be exported as module definition, for example `$`\n\n#### options.dependencies\nType: `Object`\nDefault value: `{}`\n\nAn object containing amd-dependencies as keys and the variable names they should have in the definition body, for example `{jquery: $}`\n\n#### options.globals\nType: `Array`\nDefault value: `[]`\n\nAn array containing global keys, for example `[$, jQuery]` Pass an object to expose references to global scope, i.e. {$: $} or {jQuery: myJQuery} \n\n### Usage Examples\n\n#### jQuery\nJQuery already registers as amd-module, so we only want to hide our imported version from the global scope:\n\n```js\ngrunt.initConfig({\n  amd_shim: {\n    jquery: {\n      options: {\n        globals: ['$', 'jQuery'] \n      },\n      files: {\n        'dest/jquery.js': ['test/fixtures/jquery.min.js'],\n      }\n    }\n  }\n});\n```\n\n#### MediaElement.js\nTo make MediaElement.js work as 3rd-party amd-module, generally we need to include jQuery as dependency, hide / preserve global objects 'mejs' and 'MediaElement' and export the private 'mejs'-reference.\n\nProblem here is, that a flash-plugin will still communicate over a global object named 'mejs.MediaPluginBridge'.  \nThe global bridge identifier is hardcoded in the flash source. So you may need to fork a recent version and provide a patch to make the bridge identifier configurable via flashvars. Note that there are no changes required to mediaelement.js. \n\nTo rename the global 'mejs'-object you can specify an object containing key/value-pairs as 'global'-option:\n\n```js\ngrunt.initConfig({\n  amd_shim: {\n    mediaelement: {\n      options: {\n        exports: 'mejs', \n        dependencies: {\n          jquery: '$'\n        }, \n        globals: {\n          mejs: 'my_mejs', \n          MediaElement: ''\n        }\n      },\n      files: {\n        'dest/mediaelement.js': ['src/mediaelement-and-player.min.js']\n      }\n    }\n  }\n});\n```\n\nIn order to make mediaelement.swf work with our renamed global, you will also need to set some default options. \nThis is an example using requirejs: \n```js\n// main.js\ndefine('mediaelement', [\n  'require', \n  'jquery', \n  'mediaelement-and-player'\n], function(require, $, mejs) {\n  \n  // set defaults\n  mejs.MediaElementDefaults.pluginVars = \"bridge=my_mejs.MediaPluginBridge\";\n  mejs.MediaElementDefaults.pluginPath = require.toUrl('lib/mediaelement/build/');\n  \n  return mejs;\n});\n\nrequire(['mediaelement'], function(mejs) {\n  // init player\n  var player1 = new mejs.MediaElementPlayer('#player1');\n});\n```\n  \n## Contributing\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).\n\n## Release History\n_(Nothing yet)_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenignware%2Fgrunt-amd-shim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenignware%2Fgrunt-amd-shim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenignware%2Fgrunt-amd-shim/lists"}