Skip to content

Instantly share code, notes, and snippets.

@shanecp
Created May 13, 2014 02:08
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 shanecp/8047711dd2b71389b23e to your computer and use it in GitHub Desktop.
Save shanecp/8047711dd2b71389b23e to your computer and use it in GitHub Desktop.
Sample Gruntfile.js to watch CSS/JS/PHP files for updates, concatenate and livereload them on a browser.
/*!
* [Enter your project name] Gruntfile
* http://example.com
* @author Shane Perera
*/
'use strict';
/**
* Grunt Module
*/
module.exports = function(grunt) {
/**
* Configuration
*/
grunt.initConfig({
/**
* Get package meta data
*/
pkg: grunt.file.readJSON('package.json'),
/**
* Set project object
*/
project: {
app: 'app',
assets: 'public',
css: [
'<%= project.assets %>/sass/starter-template.scss'
],
js: [
'<%= project.assets %>/js/*.js'
]
},
/**
* Project banner
*/
tag: {
banner: '/*!\n' +
' * <%= pkg.name %>\n' +
' * <%= pkg.title %>\n' +
' * <%= pkg.url %>\n' +
' * @author <%= pkg.author %>\n' +
' * @version <%= pkg.version %>\n' +
' * Copyright <%= pkg.copyright %>. <%= pkg.license %> licensed.\n' +
' */\n'
},
/**
* Sass
*/
sass: {
dev: {
options: {
style: 'expanded'
},
files: {
'<%= project.assets %>/css/style.css': '<%= project.css %>'
}
},
dist: {
options: {
style: 'compressed'
},
files: {
'<%= project.assets %>/css/style.css': '<%= project.css %>'
}
}
},
concat: {
dev: {
src: ['<%= project.assets %>/js/backbone/src/**/*.js'],
dest: '<%= project.assets %>/js/backbone/dist/app.js'
}
},
jshint: {
beforeconcat: ['<%= project.assets %>/js/backbone/src/**/*.js'],
afterconcat: ['<%= project.assets %>/js/backbone/dist/app.js']
},
/**
* CSSMin
* CSS minification
* https://github.com/gruntjs/grunt-contrib-cssmin
*/
// cssmin: {
// dev: {
// files: {
// 'public/css/style.min.css': [
// '<%= project.assets %>/bower/normalize-css/normalize.css',
// 'public/css/style.css'
// ]
// }
// },
// dist: {
// options: {
// banner: '<%= tag.banner %>'
// },
// files: {
// 'public/css/style.min.css': [
// '<%= project.assets %>/bower/normalize-css/normalize.css',
// 'public/css/style.css'
// ]
// }
// }
// },
/**
* Watch
*/
watch: {
sass: {
files: '<%= project.assets %>/sass/{,*/}*.{scss,sass}',
// tasks: ['sass:dev', 'cssmin:dev']
tasks: ['sass:dev'],
options: {
livereload: true
}
},
js: {
files: '<%= project.assets %>/js/backbone/src/**/*.js',
tasks: ['jshint:beforeconcat', 'concat:dev', 'jshint:afterconcat'],
options: {
livereload: true
}
},
project: {
files: ['app/views/**/*.blade.php', 'app/controllers/**/*.php'],
options: {
livereload: true
}
},
}
});
/**
* Load Grunt plugins
*/
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
/**
* Default task
* Run `grunt` on the command line
*/
grunt.registerTask('default', [
'sass:dev',
'jshint:beforeconcat',
'concat:dev',
// 'cssmin:dev',
'watch'
]);
/**
* Build task
* Run `grunt build` on the command line
* Then compress all JS/CSS files
*/
grunt.registerTask('build', [
'sass:dist'
]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment