Last active
February 22, 2019 11:57
-
-
Save AchrafKassioui/b5f0646750805fed322c695d0fbef21f to your computer and use it in GitHub Desktop.
Boilerplate for JavaScript plugin with export
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
| // Based on https://github.com/highlightjs/highlight.js/blob/master/src/highlight.js | |
| (function(factory) { | |
| // Find the global object for export to both the browser and web workers. | |
| var globalObject = typeof window === 'object' && window || typeof self === 'object' && self; | |
| // Setup MyPlugin.js for different environments. First is Node.js or CommonJS. | |
| if(typeof exports !== 'undefined') { | |
| factory(exports); | |
| } else if(globalObject) { | |
| // Export MyPlugin globally even when using AMD for cases when this script | |
| // is loaded with others that may still expect a global MyPlugin. | |
| globalObject.MyPlugin = factory({}); | |
| // Finally register the global MyPlugin with AMD. | |
| if(typeof define === 'function' && define.amd) { | |
| define([], function() { | |
| return globalObject.MyPlugin; | |
| }); | |
| } | |
| } | |
| }(function(MyPlugin) { | |
| // Code goes here | |
| return MyPlugin; | |
| })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment