Search code examples
angularjsgruntjsminifygrunt-contrib-uglifygruntfile

Minify typescript files using Grunt


I wanted to minify typescript files in my angular app.I tried by giving grunt command in my Gruntfile.js as

  uglify:{

            ts:{
                src:['test/scripts/**/*.ts'],
                dest:'test/scripts/**/*.ts'
            },

            js:{
                src:['test/scripts/hr.js'],
                dest:'test/scripts/hr.js'
            }
        }

When I ran the command grunt uglify The js files were uglified but not the ts files.How can I minify ts files?


Solution

  • This is the way you should write your gruntfile:

    grunt.initConfig({
    
      pkg: grunt.file.readJSON('package.json'),
    
      typescript: {
        base: {
            src:['test/scripts/**/tsfile.ts'],
                dest:'test/scripts/**/tsfile.js'
            options: {
                sourcemap: true,
                declaration: false
            }
        }
      },
    
      uglify: {
        dist: {
            files: {
                'test/scripts/**/tsfile.min.js': ['test/scripts/**/tsfile.js'],
                'test/scripts/hr.js' : ['test/scripts/hr.js']
            }
        }
      }
    
    });