Skip to content

Instantly share code, notes, and snippets.

@nareeboy
Created February 11, 2014 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nareeboy/8931583 to your computer and use it in GitHub Desktop.
Save nareeboy/8931583 to your computer and use it in GitHub Desktop.
GRUNT: Final Compiler
/**
* Grunt task to watch, compile/concate less, concate javascript files during the development process.
* The bulid task also uglyfy javascript and css file and optimize the images.
* @todo: Screenshot on difffeent break points for responsive design
* @todo: Automatic testing
*
* @author Naresh Shan
* @Naresh-shan.com.
* @since 11/02/2014
* @version 1.0
*/
var scripts = [];
var exteranlScripts = [
// 'Src/lib/jquery/jquery-1.10.2.js',
// 'Src/lib/bootstrap/js/affix.js',
// 'Src/lib/bootstrap/js/alert.js',
// 'Src/lib/bootstrap/js/button.js',
// 'Src/lib/bootstrap/js/dropdown.js',
// 'Src/lib/bootstrap/js/scrollspy.js',
// 'Src/lib/bootstrap/js/transition.js',
// 'Src/lib/bootstrap/js/collapse.js',
// 'Src/lib/bootstrap/js/modal.js',
// 'Src/lib/bootstrap/js/tooltip.js',
// 'Src/lib/bootstrap/js/popover.js',
// 'Src/lib/bootstrap/js/tab.js',
];
var projectScript = [
];
var initScripts = [
'Src/js/application.js',
];
var scripts = exteranlScripts.concat(projectScript,initScripts);
var less = ['Src/less/*.less','Src/less/**/*.less'];
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
options: {
force: true
},
all: scripts
},
concat: {
dist: {
src: scripts,
dest: 'app/assets/js/scripts.js'
}
},
uglify: {
min: {
files: {
'app/assets/js/scripts.js': ['app/assets/js/scripts.js']
}
}
},
less: {
development: {
options: {
},
files: {
"app/assets/css/style.css": 'Src/less/main.less'
}
},
production: {
options: {
yuicompress: true
},
files: {
"app/assets/css/style.css": 'Src/less/main.less'
}
}
},
smushit: {
images: {
src: ['src/img/**/*.{png,jpg,jpeg,gif}']
}
},
watch: {
options: {
livereload: true
},
scripts: {
files: scripts,
tasks: ['jshint', 'concat']
},
styles: {
files: less,
tasks: ['less:development']
},
htm: {
files: 'app/*.htm'
}
},
connect: {
server: {
options: {
base:'app/',
port: 8888,
hostname: '*'
}
}
},
copy: {
main: {
files: [
// includes files within path
{expand: true, src: ['path/*'], dest: 'dest/', filter: 'isFile'},
// includes files within path and its sub-directories
{expand: true, src: ['path/**'], dest: 'dest/'},
// makes all src relative to cwd
{expand: true, cwd: 'path/', src: ['**'], dest: 'dest/'},
// flattens results to a single level
{expand: true, flatten: true, src: ['path/**'], dest: 'dest/', filter: 'isFile'}
]
}
},
open: {
all: {
// Gets the port from the connect configuration
path: 'http://localhost:<%= connect.server.options.port%>/index.htm'
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-smushit');
grunt.loadNpmTasks('grunt-open');
grunt.loadNpmTasks('grunt-contrib-copy');
// Development task checks and concatenates JS, compiles Less, runs dev server, and starts watch
grunt.registerTask('default', ['jshint','concat', 'less:development', 'open', 'connect','watch']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment