1

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?

Nidhish Krishnan
  • 20,593
  • 6
  • 63
  • 76
forgottofly
  • 2,729
  • 11
  • 51
  • 93
  • You will want to uglify the `.js` files AFTER they have been compiled to JavaScript. This makes it a two step process if you use grunt to compile your TypeScript. – Martin Apr 16 '15 at 12:55
  • @Martin .So I can't directly minify/uglify the typescript files. – forgottofly Apr 16 '15 at 12:56
  • 3
    No you cannot. And if you could, why would you want to? No one should ever see the TypeScript besides the developers who are reading and writing the TypeScript. TypeScript is your source code, it will never be sent to the browser. JavaScript is your object code that is sent to the browser and run in the browsers JavaScript VM (or on a server running NodeJS). JavaScript sent to the browser SHOULD be uglified. – Martin Apr 16 '15 at 13:01

1 Answers1

2

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']
        }
    }
  }

});
Saba
  • 3,418
  • 2
  • 21
  • 34