Last active
August 29, 2015 14:00
-
-
Save wehrhaus/11258679 to your computer and use it in GitHub Desktop.
Require.js config with noConflict jQuery released back into the wild
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
'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(); | |
}); | |
}); |
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
/** | |
* 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); | |
}); |
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
/js | |
/libs | |
jquery-private.js | |
jquery.js | |
config.js | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment