underscore-template-loader icon indicating copy to clipboard operation
underscore-template-loader copied to clipboard

Escaping does not work

Open jantimon opened this issue 8 years ago • 3 comments

When using the escape feature of lodas/underscore templates I receive "ERROR in ReferenceError: _ is not defined"

<%- "<a href='demo'>link</a>' %>

jantimon avatar Jan 15 '16 17:01 jantimon

Ah yes it assumes you use _ as a global, but that does not make much sense.

SpaceK33z avatar Jan 15 '16 18:01 SpaceK33z

Ouch, I didn't even know this feature even existed... But here's what I noticed: when using lodash to translate a template to a function this can be found on some translations:

__e = _.escape

This can be tested by uninstalling underscore and installing lodash instead. Weird enough, this only happens on some tests, the first and second tests on loaderTests.js. I tried several versions on lodash and the problem still persists. I'm not a big fan of this library so I'm not capable of telling if there's a special type of configuration that could avoid this output. These kinds of issues could be managed much better by creating another package and moving all compatibiliity code to support lodash there.

tl;dr Someone should create a lodash-template-loader

emaphp avatar Jan 15 '16 21:01 emaphp

In my minimalistic fallback loader I just add lodash as dependency to the template:

https://github.com/ampedandwired/html-webpack-plugin/blob/feature/loaders/lib/loader.js#L25

jantimon avatar Jan 19 '16 06:01 jantimon