How can I use lodash in dojo?

494 views Asked by At

Is there a module for lodash that I can import into my dojo project? I know that I can always reference it by window._, but I wanted to be more conventional (as far as dojo is concerned) and formally require it into my module.

Thanks in advance.

1

There are 1 answers

2
Kyle Dodge On BEST ANSWER

Have you tried the AMD branch? https://github.com/lodash/lodash/tree/3.9.3-amd

You should then be able to add it to your packages, and require it in like any other module.

Edit: It worked locally by adding lodash to the packages to my dojoConfig object

var dojoConfig = {
    async: true,
    baseUrl: '.',
    packages: [
        'app',
        'dgrid',
        'dijit',
        'dojo',
        'dojox',
        'put-selector',
        'xstyle',
        'lodash'
    ],
    selectorEngine: 'lite',
    tlmSiblingOfDojo: false
};

I was then able to use the lodash modules:

define(['lodash/array/union'], function (union) {
    var app = {};

    // Lodash example
    var employees = ['John', 'Sam', 'Bob'],
        employees2 = ['Jane', 'Kari', 'Jamie'];

    console.log(employees);
    console.log(employees2);
    console.log('=== Union Result ===');
    console.log(union(employees, employees2));

    return app;
});