wwwuser wwwuser - 7 months ago 65
Javascript Question

grunt-contrib-htmlmin how to ignore template tags

I'm using grunt-contrib-htmlmin to minify my html in a backbone/underscorejs project, however, when I run grunt-contrib-htmlmin on any underscorejs template that has <%= myvar %>, the task outputs a parse error. Is there a way grunt-contrib-htmlmin can ignore text inside <%= and %>?

Answer

Since you posted this issue, an new feature was introduced into html-minifier (which is used by grunt-contrib-htmlmin) to ignore the interpolation tags that were causing the problem.

For instance, the following html partial:

<div>
    <span><%= variable %></span>
</div>

Will now minify to:

<div><span><%= variable %></span></div>

Before the changes, it would have resulted in an error.

You can try this using the demo on the website to test it out. If that works, you can update your project to make use of the new version.