Skip to content

Instantly share code, notes, and snippets.

@AchrafKassioui
Last active February 22, 2019 11:57
Show Gist options
  • Select an option

  • Save AchrafKassioui/b5f0646750805fed322c695d0fbef21f to your computer and use it in GitHub Desktop.

Select an option

Save AchrafKassioui/b5f0646750805fed322c695d0fbef21f to your computer and use it in GitHub Desktop.
Boilerplate for JavaScript plugin with export
// 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