2

I am using grunt-contrib-jst to precompile my templates and it's all working great. However, I am using this to build a plugin and I want to keep the filesize as small as possible.

I don't use underscore.js in my code, but the precompiled templates seem to have it as a dependency. Here is a sample:

template = function(obj) {
    obj || (obj = {});
    var __t, __p = '', __e = _.escape;
    with (obj) {
    __p += '<div>\n</div>';

    }
    return __p
};

As you can see, the snippet __e = _.escape requires underscore.js, but the template doesn't use __e at all.

Is there any way I can force grunt-contrib-jst to compile templates in a way so they don't require underscore.js?

Cosmin Stamate
  • 145
  • 1
  • 1
  • 11
  • Can you declare a global variable (`_ = {}`) somewhere? Also, are you sure that `_.escape()` isn't used in _any_ of your templates? – robertklep Jun 26 '15 at 06:36
  • I would like to avoid polluting the global namespace, as this is an Google Analytics-like plugin. Doing that will break that variable for any website that uses it. And I think `_.escape()` is used when you have variables that you want escaped (`<%- %>`) in the template, which I won't have (I will only use `<%= %>`). – Cosmin Stamate Jun 26 '15 at 06:48
  • You wouldn't necessarily have to use a global variable, depending on your code you might be able to wrap it with an IIFE so the `_` would be scoped to that function only. – robertklep Jun 26 '15 at 07:26
  • Yeah, I don't know how I didn't see that. Thanks, I'll give that a go! – Cosmin Stamate Jun 27 '15 at 08:06

0 Answers0