Last active
February 11, 2024 22:47
-
-
Save jaridmargolin/9010540 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(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 () { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just released AMDClean
1.2.1
, which added theprefixMode
option. You can now have all of your modules use camelCase instead of underscores. If that's not enough, you can use the newprefixTransform
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 awindow.escodegen.generate
method.