Skip to content

Commit

Permalink
added watch task
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakshmi Narayanan committed Jun 19, 2017
1 parent 67abdaf commit 6580c89
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 56 deletions.
116 changes: 67 additions & 49 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,82 @@
module.exports = function(grunt) {

// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);
var port = 9000 + ((Math.random() * 10) | 0);
console.log(port);

grunt.initConfig({
grunt.initConfig({

watch: {
scripts: {
files: ['src/**/*.js'],
tasks: ['default'],
options: {
spawn: false,
livereload: {
host: 'localhost',
port: 35729,
files: ['src/**/*.js']
portSetting: {
port: port
},

connect: {
server: {
options: {
livereload: true,
base: 'src/',
port: '<%= portSetting.port %>'
}
}
},
},
},

clean: {
js: ['src/js/all.min.js', 'src/js/all.js']
},
open: {
server: {
path: 'http://localhost:<%= portSetting.port %>',
app: 'firefox'
}
},

concat: {
options: {
separator: ';'
watch: {
scripts: {
files: ['src/js/*.js', '!src/js/all.min.js', '!src/js/all.js'],
tasks: ['clean', 'jshint', 'concat', 'uglify'],
options: {
livereload: true
},
},
},
dist: {
src: ['src/**/*.js'],
dest: 'src/js/all.js'
}
},

uglify: {
dist: {
files: {
'src/js/all.min.js' : ['src/js/all.js']
}
}
},
clean: {
js: ['src/js/all.min.js', 'src/js/all.js']
},

jshint: {
files: ['Gruntfile.js', 'src/**/*.js'],
options: {
globals: {
console: true,
module: true
}
concat: {
options: {
separator: ';'
},
dist: {
src: ['src/**/*.js'],
dest: 'src/js/all.js'
}
},

uglify: {
dist: {
files: {
'src/js/all.min.js': ['src/js/all.js']
}
}
},

jshint: {
files: ['Gruntfile.js', 'src/**/*.js'],
options: {
globals: {
console: true,
module: true
}
}
}
}

});
});

grunt.registerTask('default', ['clean', 'jshint', 'concat', 'uglify', 'watch']);
grunt.registerTask('testjs', ['jshint']);
grunt.registerTask('concatjs', ['concat']);
grunt.registerTask('uglifyjs', ['uglify']);
grunt.registerTask('watchjs', ['watch']);
grunt.registerTask('cleanjs', ['clean']);
grunt.registerTask('default', ['clean', 'jshint', 'concat', 'uglify', 'connect', 'open', 'watch']);
grunt.registerTask('testjs', ['jshint']);
grunt.registerTask('concatjs', ['concat']);
grunt.registerTask('uglifyjs', ['uglify']);
grunt.registerTask('watchjs', ['watch']);
grunt.registerTask('cleanjs', ['clean']);
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
"grunt": "~0.4.1",
"grunt-contrib-clean": "^1.1.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-connect": "^1.0.2",
"grunt-contrib-jshint": "~0.6.0",
"grunt-contrib-uglify": "0.2.2",
"grunt-contrib-watch": "~0.4.4",
"grunt-open": "^0.2.3",
"load-grunt-tasks": "^3.5.2",
"time-grunt": "^1.4.0"
},
Expand Down
4 changes: 2 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<title>Grunt Config</title>
</head>
<body>
<h1>Hello World</h1>
<script src="//localhost:35729/livereload.js"></script>
<h1>Hello Lakshmi</h1>
<script src="//localhost:35729/livereload.js"></script>
<script src="js/all.min.js"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions src/js/all.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function sum() {
return 'Hello World';
return 'Hello Lakshmi';
}

var sumed = sum();
Expand All @@ -8,4 +8,4 @@ document.body.innerHTML = sumed;
alert(message);
}

say("Lakshmi Narayanan");
say("Hello World !");
2 changes: 1 addition & 1 deletion src/js/all.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/js/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function sum() {
return 'Hello World';
return 'Hello Lakshmi';
}

var sumed = sum();
Expand Down
2 changes: 1 addition & 1 deletion src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ function say(message) {
alert(message);
}

say("Lakshmi Narayanan");
say("Hello World !");

0 comments on commit 6580c89

Please sign in to comment.