I'm setting up a way for me to keep my preferred requireJS way of working and integrate this with Wordpress.
The big issue being how then to load jquery. Wordpress loads jQuery via wp_enqueue_script which needs to remain that way as some Wordpress plugins I regularly use need jquery to be added that way. I don't then want to load a second version of jQuery within my requireJS setup. So, after some looking around this is what I've come up with:
templates/footer.php
<script>
if (typeof jQuery === 'function') {
define( 'jquery', function () { return jQuery; } );
}
require(['/assets/js/sample-common.js'], function (common) {
require(['sample-bootstrapper']);
});
</script>
Which sees if jQuery has already been added to the page, if it has been then it sets it as the module value.
My question is should I then just leave jquery to be in the global namespace, or follow these instructions:
http://requirejs.org/docs/jquery.html#noconflictmap
The problem with the above is I will probably need to include jquery plugins that aren't AMD compatible, is it worth the effort to make them AMD compatible or another solution I thought about was removing the true from the noConflict declaration which keeps the 'jQuery' in the global namespace allowing the plugins to function.
This is less of a question and more of a call for best practice advice. And any would be much appreciated!
Thanks!