【问题标题】:grunt-contrib-uglify doesn't minify the object propertygrunt-contrib-uglify 不会缩小对象属性
【发布时间】:2017-09-02 21:54:28
【问题描述】:

我想使用 Grunt 的 grunt-contrib-uglify 包来缩小我的 JS 代码。我的项目的 JS 文件是这样的:

// src/js/script.js
var app = new Vue({
  el: "...",
  data: {...},
  computed: {...},
  methods: {...},
  beforeMount() {...} // line 902
});

虽然未缩小的代码可以正常工作,但 Uglify 在到达第 902 行时会抛出错误。我猜这是因为声明 beforeMount() 的方式不是标准的 JavaScript。如果我删除它,script.js 被缩小没问题。不幸的是,这对项目至关重要,我想不出另一种解决方法。

我尝试过使用grunt --force,但它没有输出任何内容。

我有兴趣让 Grunt 缩小这一点,或者替代 Grunt 做同样的工作。谢谢:)

【问题讨论】:

    标签: javascript ecmascript-6 gruntjs minify grunt-contrib-uglify


    【解决方案1】:

    你几乎是对的。 beforeMount() 的语法是类方法(es6)的声明,但这是一个对象属性。

    你应该使用这个语法:

    beforeMount: function() {...}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-30
      • 1970-01-01
      • 2013-11-04
      • 1970-01-01
      • 2014-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多