emaphp / underscore-template-loader

A Underscore and Lodash template loader for Webpack
MIT License
104 stars 24 forks source link

Escaping does not work #13

Open jantimon opened 8 years ago

jantimon commented 8 years ago

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

<%- "<a href='demo'>link</a>' %>
SpaceK33z commented 8 years ago

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

emaphp commented 8 years ago

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

jantimon commented 8 years ago

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