Making a JavaScript File AMD Compliant For Use With RequireJS

So I had to use a library that adds some features to Google Maps, it's called MarkerClusterer. I copied the file into my vendor directory and then realized it is not AMD compliant. My first thought was to put the define() wrapper around the code in the file, to make it compliant. And that actually worked, but I soon realized there is a better way. In the main.js file you can use a 'shim' and 'exports', like so:

 

require.config({
baseUrl: 'js',
paths: {
'jquery': '../vendor/jquery/jquery',
'underscore': '../vendor/underscore-amd/underscore',
'backbone': '../vendor/backbone-amd/backbone',
'async':'../vendor/requirejs-plugins/src/async',
'markerclusterer': '../vendor/markerclusterer/index'
},

shim:{
'markerclusterer':{
exports: "MarkerClusterer"
}
}

});

require(["router"],

function(Router) {
return new Router();
}

);

 

Then you can us it like any other dependency when you create a module:

 

define([
'jquery',
'underscore',
'backbone',
'markerclusterer',
'async!http://maps.google.com/maps/api/js?sensor=false'
],function($, _, Backbone, MarkerClusterer){

var Map = Backbone.View.extend({

//code goes here

});

return Map

});

 

 

 

Add a Comment...

 

Comments

Absolutely NEW update of SEO/SMM software "XRumer 16.0 + XEvil": captcha solving of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another categories of captcha, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM programms: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms. Interested? There are a lot of demo videos about XEvil in YouTube. Good - 7/22/2017

best rated mattresses 2017 consumer reports best mattress 2017 the best mattress 2017 best rated mattress for 2017 top 5 hybrid mattress 2017 top rated mattresses for 2017 top ten mattresses 2017 best rated mattress 2017 best rated mattresses 2017 best mattresses to buy online 2017 best memory foam mattress 2017 best rated hybrid mattresses 2017 best memory foam mattress 2017 best mattress to buy 2017 best mattress to buy for 2017 casper bed promo code casper bed coupon code coupons ca - 7/22/2017

Revolutional update of SEO/SMM software "XRumer 16.0 + XEvil 3.0": captchas regignizing of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another types of captcha, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM programms: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software. Interested? There are a lot of introducing videos about XEvil in YouTube. - 7/22/2017

Absolutely NEW update of SEO/SMM package "XRumer 16.0 + XEvil 3.0": captcha solution of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another size-types of captcha, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software. Interested? There are a lot of demo videos about XEvil in YouTube. Goo - 7/22/2017

Revolutional update of SEO/SMM software "XRumer 16.0 + XEvil 3.0": captcha recognition of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another size-types of captchas, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms. Interested? You can find a lot of demo videos about XEvil in YouTube - 7/21/2017

Revolutional update of SEO/SMM package "XRumer 16.0 + XEvil 3.0": captchas solving of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another types of captchas, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM programms: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms. Interested? You can find a lot of introducing videos about XEvil in YouTube. - 7/18/2017

Absolutely NEW update of SEO/SMM package "XRumer 16.0 + XEvil": captchas solution of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another categories of captcha, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms. Interested? There are a lot of demo videos about XEvil in YouTube. See y - 7/17/2017

Absolutely NEW update of SEO/SMM package "XRumer 16.0 + XEvil": captcha recognition of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another subtypes of captchas, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM programms: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software. Interested? There are a lot of demo videos about XEvil in YouTube. See - 7/14/2017

SHBMichel Island SandraDea Bridgette Mexico Constance BABRoryh Olympique De Marseille BlondellS GroverBim Tottenham Hotspurs BillPapst Tabithamt Turkiet LeonorSpa AugustusL AC Milan GladysVas JaiTalbot BVB Borussia Dortmund KristinaW Zitatjaqv Juventus NicholSer BirgitStr Portugal IrmaStret MaryjoGra West Ham United ErinDawes Brianneiw Danmark DanutaTep MaggieCjy Valencia RemonaCha RhondaMah Chile DongMeban MichelBar Slovakien Frederick JennieBcv Chelsea PaulinaRo - 6/29/2017

Hello There. I found your weblog the use of msn. This is a very smartly written article. I'll be sure to bookmark it and return to read extra of your useful info. Thanks for the post. I'll definitely return. liverpool kläder - 5/16/2017

pmwiki forum projecthomelessconnectbutte simulationgame aceplay ogir blackfarmers safleetwash citticaffe zdfdsb - 5/09/2017

Hi everyone, it's my first pay a quick visit at this web page, and post is actually fruitful in favor of me, keep up posting these types of content. maglie calcio bambini - 4/27/2017

LouieHeym Portugal DaltonBer Anastasia Kroatien BeatrizOr ChristyCl Slovakien LorrieXci QGWTerry Olympique Lyonnais CarmonHav AngelinaM Island Concettaj - 3/07/2017