webpack: An error in UglifyJSPlugin when using html-loader

I use webpack and UglifyJSPlugin to build my backbone application. When building this application an error arises.

ERROR in ./~/html-loader!./templates/messageTemplate.html
Module build failed:
 @ ./js/message-view.js 1:22-72

I have two undersore’s templates:

<!-- first template -->
<label><%- prompt %></label>
<!-- second template -->
<div <%= color ? ('style="color:' + color + '"') : '' %>>
    <%= link ? ('<a href="' + link + '">') : '' %>
        <%= message %>
    <%= link ? ('</a>') : '' %>
</div>

Only the second template have an error.

I would like to know whether I need to write a configuration in UglifyJSPlugin to fix the problem.

Thank you!

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 1
  • Comments: 19 (7 by maintainers)

Most upvoted comments

@bebraw I can (assuming the issue still stems). When running webpack -p to minimize templates as well as JS, I get a very obscure “module failed error: Parser Error” and it just outputs whatever it was trying to build. The way I got around this issue, for now, is setting minimize to false under:

plugins: [
        new webpack.LoaderOptionsPlugin({
            test: /\.html$/,
            options: {
                htmlLoader: {
                    ignoreCustomFragments: [/\{\{.*?}}/],
                    minimize: false
                },
            }
       })
   ]

It isn’t ideal, but it does allow me to import HTML fragments in legacy Dojo code that we are trying to work on converting to ES6 and eventually migrating to React.

Try &lt; instead of < (which is invalid inside html blocks)

I think I’m seeing the same problem, but more serious since it cannot be worked around.

Angular2 requires attributes like <a (click)="..." [something]="..."> which seem to trigger the same error when using UglifyJsPlugin.