I am trying to minify an angularjs application using grunt and terser. I first used uglifiy-es but then read that it has some issues. So I tried terser. But the output does not give me minified files.
The gruntfile.js
    module.exports = function(grunt) {
  grunt.initConfig({
      pkg: grunt.file.readJSON('package.json'),
        //grunt task configuration will go here
        ngAnnotate: {
          options: {
              singleQuotes: true
          },
          app: {
              files: {
                  './public/min-safe/js/_config_min.js': ['./controllers/_config.js'],
                  './public/min-safe/js/ctrl_accountingdashboard.js': ['./controllers/ctrl_accountingdashboard.js'], 
              }
          }
      },
      concat: {
        js: { //target
            src: ['./public/min/app.js', './public/min-safe/js/*.js'],
            dest: './public/min/app.js'
        }
    },
    terser: {
      options: {},
      files: {
        './public/min/app.js': ['./public/min/app.js'],
      },
    }
  });
  //load grunt tasks
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-terser');
  grunt.loadNpmTasks('grunt-ng-annotate'); 
  //register grunt default task
  grunt.registerTask('default', ['ngAnnotate', 'concat', 'terser']);
}
I had the same problem. According to the documentation, this should work but it didn't for me. Wrapping the "files" setting in a custom target works for me:
terser: {
  options: {},
  main: {
    files: {
      './public/min/app.js': ['./public/min/app.js'],
    }
  }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With