Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wehrhaus/11258679 to your computer and use it in GitHub Desktop.
Save wehrhaus/11258679 to your computer and use it in GitHub Desktop.
Require.js config with noConflict jQuery released back into the wild
'use strict';
var cpApp = require.config({
// set baseUrl from require script
baseUrl: document.querySelector('.requireScript').getAttribute('data-base-url'),
// set a context for modules
context: 'cpApp',
// To get timely, correct error triggers in IE, force a define/shim exports check.
enforceDefine: true,
map: {
// give all modules 'jquery-private' for the 'jquery' module
// which returns noConflict and releases jQuery back to the global namespace
// we do this to ensure jQuery will be available outside of require
'*': {'libs/jquery': 'libs/jquery-private'},
// give 'jquery-private' the real jquery module
// to avoid cyclic dependency
// Any modules using jquery will need to use the AMD return
// rather than depending on global '$'
// GOOD Example: require(['jquery'], function ($) { console.log($); // OK });
// BAD Example: require(['jquery'], function () { console.log($); // UNDEFINED });
'jquery-private': {'jquery': 'jquery'}
},
paths: {
jquery: [
'//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min',
'libs/jquery'
],
bootstrap: 'libs/bootstrap.min.js'
},
shim: {
bootstrap: {
deps: ['jquery'],
exports: 'Bootstrap'
},
bxslider: {
deps: ['order!jquery', 'order!libs/jquery.bxslider.min', 'order!jquery.fitvids'],
exports: 'bxSlider'
}
},
urlArgs: 'bust=' + (new Date()).getTime()
});
cpApp(['jquery', 'app'], function ($, app) {
$(document).ready(function () {
return app.appHello();
});
});
/**
* Return jQuery with noConflict(true) to the global namespace
*/
define(['jquery'], function (jq) {
'use strict';
// this module is delivered to all other require modules expecting 'jquery'
return jq.noConflict(true);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment