Skip to content

Instantly share code, notes, and snippets.

@krasenslavov
Last active January 3, 2022 09:02
Show Gist options
  • Save krasenslavov/652b7d60a7626cb06d0fee4a75da12a3 to your computer and use it in GitHub Desktop.
Save krasenslavov/652b7d60a7626cb06d0fee4a75da12a3 to your computer and use it in GitHub Desktop.
How to Setup JS and CSS Environment Files (no external libraries)
var UUID = UUID || {};
var $ = jQuery || {};
UUID.pluginURL = 'https://example.com/wp-content/themes/uuid/';
UUID.loadModules = function ()
{
if (this.pluginURL) {
var jsURL = this.pluginURL + 'assets/js/';
this.require(jsURL + 'utils.mjs');
this.require(jsURL + 'module1.mjs');
this.require(jsURL + 'module2.mjs');
this.require(jsURL + 'module3.mjs');
} else {
throw new Error('Base URL is not defined!');
}
};
UUID.require = function (script)
{
$.ajax({
url: script,
dataType: 'script',
async: true,
success: function () {},
error: function () {
throw new Error('Could not load script ' + script);
}
});
};
(function ($, undefined) {
UUID.loadModules();
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment