javascript - requireJS load non AMD common scripts -
how load non-amd complaint scripts common in requirejs or should have manually? speaking of jquery, bootstrap , other little scripts needed globally custom modules.
you can still ask requirejs load library need use "shim" functionality in requirejs.config() call specified here:
http://requirejs.org/docs/api.html#config-shim
if i've understood asking, here example (i didn't see if bootstrap exposed global or mixed in jquery you'll see point):
requirejs.config({ paths: { 'jquery': 'path/to/jquery/jquery.min', 'bootstrap': 'path/to/bootstrap/bootstrap.min' }, shim: { 'bootstrap': { deps: ['jquery'], exports: 'bootstrap' } } }); require(['bootstrap'], function(bootstrap) { /* because of specified dependencies above, requirejs load jquery first , bootstrap, supplying library function signature can use "bootstrap" variable normally. */ });
if wanted $
in scope jquery, need this:
require(['jquery', 'bootstrap'], function($, bootstrap) { // use '$' , 'bootstrap' here. }
Comments
Post a Comment