Skip to content

Instantly share code, notes, and snippets.

@jaridmargolin
Last active February 11, 2024 22:47
Show Gist options
  • Save jaridmargolin/9010540 to your computer and use it in GitHub Desktop.
Save jaridmargolin/9010540 to your computer and use it in GitHub Desktop.
;(function (id, name, context, definition) {
// --------------------------------------------------------------------------
// Dependencies
//
// This is an attempt to make this library compatible with multiple module
// formats. Other UMD implementations do not take into account dependencies:
// Example: https://github.com/ForbesLindesay/umd/blob/master/template.js
//
// **NOTE: Named AMD modules are more suitable for libraries as it provides
// a consistent naming convention to access it by (anonymous AMD modules are
// better suited on an app level where files/paths may be changed).
// --------------------------------------------------------------------------
var deps = [];
// CommonJS
if (typeof module !== 'undefined' && module.exports) {
for (var i = 0, l = deps.length; i < l; i++) {
deps[i] = require(deps[i])
};
module.exports = definition.apply(context, deps);
// AMD
} else if (typeof define === 'function' && define.amd) {
define(id, deps, definition);
// STANDARD
} else {
context[name] = definition.apply(context, deps);
}
})('amdName', 'contextName', this, function () {
@gfranko
Copy link

gfranko commented Feb 18, 2014

I just released AMDClean 1.2.1, which added the prefixMode option. You can now have all of your modules use camelCase instead of underscores. If that's not enough, you can use the new prefixTransform function hook to customize the logic yourself.

Usually, the Require.js shim configuration will work (but there are exceptions). AMDClean depends on the escodegen library, which does not work even with the shim configuration: estools/escodegen#115 (comment)

The AMDClean approach still works (even though Escodegen does not work with Require.js), since it also checks if there is a global window.escodegen object that is declared (which there is) and a window.escodegen.generate method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment