Uglifyjsplugin breaking angular 2 template

I have this uglifyjsplugin configuration in my webpack configuration file:

exports.minify = function() {
 return {
 plugins: [
  new webpack.optimize.UglifyJsPlugin({
            beautify: false,
            comments: false,
            compress: {
                warnings: false,
                drop_console: true
            },
            // Mangling specific options
            mangle: false
        })
   ]
 }
}

My problem is that uglify breaks my code if I run my build without using Uuglify code, but if I add the uglify step, I will get this error:

Unexpected closing tag "a" ("d-top"> <div class=container-fluid> <div class=navbar-header> <a href=/ class=navbar-brand>{{title}}[ERROR ->]</a> <button type=button class=navbar-toggle data-toggle=collapse data-target=.navbar-collapse> <span"): HeaderComponent@0:145

I already run many configurations for uglify, but the error persists. My original angular template that gives an error:

<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container-fluid">
    <div class="navbar-header">
      <a href="/" class="navbar-brand">{{title}}</a>
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
    <span class="sr-only">Toggle</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </button>
</div>
<ul class="nav navbar-nav navbar-right collapse navbar-collapse">
  <li><a href="#" data-toggle="dropdown">General Info</a></li>
  <li><a href="#" data-toggle="dropdown">Author</a></li>
</ul>
  </div>
    </nav>
+4
source share
2 answers

Parsing the templates does not work as expected, and the angular team has provided work on their documents right now, but I hope that this should be fixed in the webpack.config file soon.

  htmlLoader: {
    minimize: false // workaround for ng2
  },

angular.io

, @pdcc

{
    test: /\.html$/,
    loader: `html?-minimize`
}
+3

. html- :

{
    test: /\.html$/,
    loader: `html?-minimize`
}
+1

Source: https://habr.com/ru/post/1651449/


All Articles