javascript - require.js shim for lib jquery, marionette, backbone, underscore -
i used link libraries :
shim: { backbone: { deps: ["jquery", "underscore"], exports: "backbone" }, marionette: { deps: ["backbone"], exports: "marionette" }, angular: { exports: "angular" } } but have read these libs uses amd , shim property not required! it?
main.js
paths: { marionette: "backbone.marionette" } some.js
define( "util", ['marionette'], function(marionette){ //test arguments! //console.log($) //console.log(jquery) //console.log(backbone) //console.log(_) console.log(marionette) //exist! } );
if third party scripts not amd compatible have use shims.
you might check if scripts amd compatible if @ top code have this:
(function(root, factory) { // set backbone appropriately environment. start amd. if (typeof define === 'function' && define.amd) { define(['underscore', 'jquery', 'exports'], function(_, $, exports) { // export global in amd case in case script loaded // others may still expect global backbone. root.backbone = factory(root, exports, _, $); }); // next node.js or commonjs. jquery may not needed module. } else if (typeof exports !== 'undefined') { var _ = require('underscore'), $; try { $ = require('jquery'); } catch(e) {} factory(root, exports, _, $); // finally, browser global. } else { root.backbone = factory(root, {}, root._, (root.jquery || root.zepto || root.ender || root.$)); } }(this, function(root, backbone, _, $) { // .... } and here how example configuration file on 1 of project:
shim: { // jquery mobile "jquerymobile": ["jquery"], // twitter bootstrap jquery plugins "bootstrap": ["jquery"], // jqueryui "jqueryui": ["jquery"], // jquery cookie "jquery.cookie": { deps: ["jquery"], exports: "jquery.cookie" }, // jquery easing functions "jquery.easing" : { deps: ["jquery"], exports: "jquery.easing" }, // shim backbone resolve conflicts on minification "backbone": { deps: ['underscore', 'jquery'], init: function(_, $) { return this.backbone = backbone.noconflict(); } }, // backbone.validateall plugin depends on backbone "backbone.validateall": ["backbone"], "backbone.paginator" : { deps: ["backbone"], exports : "backbone.paginator" }, "backgrid" : { deps : ['jquery', 'underscore', 'backbone'], exports: "backgrid" }, "backgrid.paginator" : { deps: ["backbone", "backgrid"], exports : "backgrid.paginator" } }
Comments
Post a Comment