RequireJs only loading JQuery when I configure the path option -
my application construction looks like:
... javascripts/ - main.js lib/ - jquery-1.9.0.min.js - require.js
i have html page like:
<script type="text/javascript" data-main='/assets/javascripts/main' src='/assets/javascripts/lib/require.js'></script>
my main.js looks like:
//main.js require.config({ paths: { jquery: 'lib/jquery-1.9.0.min' }}); require(['jquery'], function($) { homecoming $(function() { homecoming console.log('dom ready'); }); });
this works fine, , html page says 'dom ready' in console. problem when remove paths configuration , seek load jquery this:
//updated main.js require(['lib/jquery-1.9.0.min'], function($) { homecoming $(function() { homecoming console.log('dom ready'); }); });
where have removed path configuration , have tried load jquery specifying path. gives me "undefined not function" in reference $ variable. strangely, still see jquery-1.9.0.min coming on network initiated require.js. going on here? bug?
not bug. jquery exports named module. means must have path configuration option.
// expose jquery amd module, amd loaders // understand issues loading multiple versions of jquery // in page might phone call define(). loader indicate // have special allowances multiple jquery versions // specifying define.amd.jquery = true. register named module, // since jquery can concatenated other files may utilize define, // not utilize proper concatenation script understands anonymous // amd modules. named amd safest , robust way register. // lowercase jquery used because amd module names derived // file names, , jquery delivered in lowercase file name. // after creating global if amd module wants phone call // noconflict hide version of jquery, work. if ( typeof define === "function" && define.amd && define.amd.jquery ) { define( "jquery", [], function () { homecoming jquery; } ); }
https://github.com/jquery/jquery/blob/master/src/exports.js
if not library still load (as you've seen) won't returned correctly require/define callback
jquery requirejs
No comments:
Post a Comment