uglifyjsplugin打破角度2模板

时间:2016-08-16 19:44:27

标签: angularjs webpack uglifyjs

我的webpack配置文件中有uglifyjsplugin的配置:

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

我的问题是uglify破坏了我的代码,如果我在没有uglify的情况下运行我的构建代码可以工作但是如果我添加uglify步骤我会收到此错误:

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

我已经为uglify运行了许多配置,但错误仍然存​​在。我给出错误的原始角度模板是:

<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>

2 个答案:

答案 0 :(得分:3)

模板解析没有正常工作,而且有远见的团队现在已经为他们的文档提供了解决方案,但希望尽快完成它 在webpack.config文件中添加此

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

workaround from angular.io

其他提及@pdcc

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

答案 1 :(得分:1)

几个小时后我找到了解决方案。在html加载器中,我们必须添加最小化:

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