grunt-contrib-uglify doesn't minify the object property

259 Views Asked by At

I'd like to minify my JS code using Grunt's grunt-contrib-uglify package. My project's JS file looks like this:

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

Although the un-minified code works fine, Uglify throws an error when it hits line 902. I'm guessing it's because the way beforeMount() is declared isn't standard JavaScript. If I remove it, script.js is minified no problem. Unfortunately, it's crucial to the project, and I can't think of another workaround.

I've tried using grunt --force, but it doesn't output anything.

I'd be interested in thoughts on getting Grunt to minify this, or alternatives to Grunt that do the same job. Thanks :)

1

There are 1 best solutions below

0
On BEST ANSWER

You are almost right. The syntax of beforeMount() is the declaration of class method (es6), but this is an object property.

You should use this syntax:

beforeMount: function() {...}