Created
May 18, 2017 16:37
-
-
Save joshuacerbito/72917266d13e3343c28baa4c59d08fb6 to your computer and use it in GitHub Desktop.
JS Module Exporter (AMD, CommonJS, Globals)
This file contains hidden or 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(globals){ | |
// module name | |
const MODULE_NAME = 'moduleName'; | |
// define your functions here | |
const functions = { | |
fn1: alert, | |
fn2: console.log | |
}; | |
function exportFunctions (functions) { | |
if (typeof define === 'function' && define.amd) { | |
// set module name for AMD-based implementations | |
define(function () { | |
return functions; | |
}); | |
} else if (typeof module !== 'undefined' && module !== null && module.exports) { | |
// set module name for CommonJS-based implementations | |
module.exports = functions; | |
} else { | |
// set module name for Global-based implementations | |
globals[MODULE_NAME] = functions; | |
} | |
} | |
exportFunctions(functions); | |
})(this) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment