Skip to content

Instantly share code, notes, and snippets.

@manchumahara
Created June 29, 2015 05:21
Show Gist options
  • Save manchumahara/63d73a5bfb320a8e2b8a to your computer and use it in GitHub Desktop.
Save manchumahara/63d73a5bfb320a8e2b8a to your computer and use it in GitHub Desktop.
// Gruntfile.js
// our wrapper function (required by grunt and its plugins)
// all configuration goes inside this function
module.exports = function(grunt) {
'use strict';
// ===========================================================================
// CONFIGURE GRUNT ===========================================================
// ===========================================================================
grunt.initConfig({
// get the configuration info from package.json ----------------------------
// this way we can use things like name and version (pkg.name)
pkg: grunt.file.readJSON('package.json'),
// configure jshint to validate js files -----------------------------------
jshint: {
options: {
reporter: require('jshint-stylish') // use jshint-stylish to make our errors look and read good
},
// when this task is run, lint the Gruntfile and all js files in src
build: ['grunfile.js', 'js/*.js']
},
// configure uglify to minify js files -------------------------------------
uglify: {
options: {
banner: '/*\n <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> \n*/\n'
},
build: {
files: {
'js/app.min.js': 'js/app.js'
}
}
},
// compile less stylesheets to css -----------------------------------------
less: {
build: {
files: {
'css/style.css': 'less/style.less'
}
}
},
// configure cssmin to minify css files ------------------------------------
cssmin: {
options: {
banner: '/*\n <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> \n*/\n'
},
build: {
files: {
'css/style.min.css': 'css/style.css'
}
}
},
// configure watch to auto update ----------------
watch: {
// for stylesheets, watch css and less files
// only run less and cssmin stylesheets: {
options: { livereload: true },
css: {
files: ['less/*.less'],
tasks: ['less'],
},
// for scripts, run jshint and uglify
/*scripts: {
files: 'js/*.js', tasks: ['jshint', 'uglify']
} */
},
browserSync: {
bsFiles: {
src : ['css/style.css', '*.html']
},
options: {
watchTask: true,
server: {
baseDir: "./"
}
}
}
// ============= // CREATE TASKS ========== //
//grunt.registerTask('default', ['jshint', 'uglify', 'cssmin', 'less']);
});
// ===========================================================================
// LOAD GRUNT PLUGINS ========================================================
// ===========================================================================
// we can only load these if they are in our package.json
// make sure you have run npm install so our app can find these
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-watch');
//grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-browser-sync');
// this default task will go through all configuration (dev and production) in each task
//grunt.registerTask('default', ['jshint', 'uglify', 'cssmin', 'less']);
// this task will only run the dev configuration
//grunt.registerTask('dev', ['jshint:dev', 'uglify:dev', 'cssmin:dev', 'less:dev']);
// only run production configuration
//grunt.registerTask('production', ['jshint:production', 'uglify:production', 'cssmin:production', 'less:production']);
//
//grunt.registerTask('default', ['browserSync','cssmin', 'less','watch']);
grunt.registerTask('default', [ 'browserSync', 'watch']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment