NodeJS 29: BuildTook with NodeJS - Using GRUNT
#######################################CODE################################
######################
Gruntfile.js
######################
module.exports=function(grunt){
//trying to merge multiple js and send it to client as one file
//when we run the command it does automatically
grunt.initConfig({
concat :{ //to concatinate all js files in to 1 file
js: {
src: ['js/1.js', 'js/2.js'],
dest: 'build/js/scripts.js',
},
css: {
src: ['css/1.css', 'css/2.css'],
dest: 'build/css/styles.css',
}
},
watch:{ //to watch for file changes and execute
js:{
files: ['js/**/*.js'],
tasks: ['concat:js'], //to call only contact : js
},
css:{
files: ['css/**/*.css'],
tasks: ['concat:css'], //to call only contact : css
}
}
});
//load this module
grunt.loadNpmTasks('grunt-contrib-concat');
//load this module
grunt.loadNpmTasks('grunt-contrib-watch');
//to automatically execute add it in 'default' section..
//CMD : grunt
grunt.registerTask('default',['concat','watch']);
}
######################
package.json
######################
{
"name": "grunt1",
"version": "1.0.0",
"description": "grunt",
"main": "1.js",
"dependencies": {
"grunt": "^1.0.3",
"grunt-cli": "^1.3.1",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-watch": "^1.1.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "pavan",
"license": "ISC"
}
######################CODE END ############################################
#######################################CODE################################
######################
Gruntfile.js
######################
module.exports=function(grunt){
//trying to merge multiple js and send it to client as one file
//when we run the command it does automatically
grunt.initConfig({
concat :{ //to concatinate all js files in to 1 file
js: {
src: ['js/1.js', 'js/2.js'],
dest: 'build/js/scripts.js',
},
css: {
src: ['css/1.css', 'css/2.css'],
dest: 'build/css/styles.css',
}
},
watch:{ //to watch for file changes and execute
js:{
files: ['js/**/*.js'],
tasks: ['concat:js'], //to call only contact : js
},
css:{
files: ['css/**/*.css'],
tasks: ['concat:css'], //to call only contact : css
}
}
});
//load this module
grunt.loadNpmTasks('grunt-contrib-concat');
//load this module
grunt.loadNpmTasks('grunt-contrib-watch');
//to automatically execute add it in 'default' section..
//CMD : grunt
grunt.registerTask('default',['concat','watch']);
}
######################
package.json
######################
{
"name": "grunt1",
"version": "1.0.0",
"description": "grunt",
"main": "1.js",
"dependencies": {
"grunt": "^1.0.3",
"grunt-cli": "^1.3.1",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-watch": "^1.1.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "pavan",
"license": "ISC"
}
######################CODE END ############################################



No comments:
Post a Comment