[Dev Tip] Auto compile typescript using grunt


1) Install grunt-cli

npm install grunt-cli -g

2) Move to your project folder (you can install grunt, typescript,.. in any folder which you want)
– install grund

npm install grunt --save-dev

– install typescript

npm install typescript --save-dev

– install grunt-typescript

npm install grunt-typescript --save-dev

– install grunt-contrib-watch

npm install grunt-contrib-watch --save-dev

– setup grunt by create Gruntfile.js.
For example:

module.exports = function (grunt) {

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
typescript: {
base: {
src: '*.ts',
dest: 'myjs.js',
options: {
module: 'amd',
target: 'es5'
}
}
},
watch: {
files: '*.ts',
tasks: ['typescript']
},
});

grunt.loadNpmTasks('grunt-typescript');
grunt.loadNpmTasks('grunt-contrib-watch');

grunt.registerTask('default', ['watch']);
};

– run grunt

grunt

– change your ts file and save it, you will automatically get js result.

You will get something like that

gruntNote: there is a nice command:

npm install
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s