Last active
January 3, 2022 09:02
-
-
Save krasenslavov/652b7d60a7626cb06d0fee4a75da12a3 to your computer and use it in GitHub Desktop.
How to Setup JS and CSS Environment Files (no external libraries)
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
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