Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terser does not give minified file

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']);

}
like image 641
Dwigh Avatar asked Jun 10 '19 05:06

Dwigh


1 Answers

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'],
    }
  }
}
like image 180
Tim Avatar answered Oct 08 '22 12:10

Tim