Skip to content

Instantly share code, notes, and snippets.

@e-river
Created January 15, 2014 09:39
Show Gist options
  • Save e-river/8433420 to your computer and use it in GitHub Desktop.
Save e-river/8433420 to your computer and use it in GitHub Desktop.
Gruntfile.js using grunt-contrib-cssmin, grunt-contrib-watch, grunt-contrib-concat, grunt-contrib-clean, grunt-contrib-compass, grunt-contrib-uglify
module.exports = function(grunt) {
var pkg = grunt.file.readJSON('package.json');
grunt.initConfig({
//Concatenate JS files
concat: {
lib: {
src: [
'public_html/dev/lib/jquery.js',
'public_html/dev/lib/jquery_easing_min.js'
],
dest: 'public_html/js/lib/lib.js'
},
dev: {
src: [
'public_html/dev/script.js',
'public_html/dev/hoge.js'
],
dest: 'public_html/js/app.js'
}
},
//compass
compass: {
dist: {
options: {
config: 'config.rb',
sassDir: 'sass',
cssDir: 'css',
imagesDir: 'img'
}
},
dev: {
options: {
config: 'config.rb',
sassDir: 'dir/sass',
cssDir: 'dir/css',
imagesDir: 'dir/img'
}
}
},
//Minify CSS files
cssmin: {
combine: {
files: {
'public_html/css/style.css': ['public_html/css/style.css']
}
}
},
//Minify JS files with UglifyJS
uglify: {
lib: {
src: 'public_html/js/lib/lib.js',
dest: 'public_html/js/lib/lib.min.js'
},
dev: {
src: 'public_html/js/app.js',
dest: 'public_html/js/app.min.js'
}
},
//Clear files
clean: [
'public_html/js/lib/lib.js',
'public_html/js/app.js'
],
//Watcing files change
watch: {
js: {
files: [
'public_html/dev/**/*.js'
],
tasks: ['concat', 'uglify']
},
scss: {
files: [
'public_html/sass/*.scss'
],
tasks: 'compass:dist'
},
scss2: {
files: [
'public_html/dir/sass/*.scss'
],
tasks: 'compass:dev'
}
}
});
var taskName;
for(taskName in pkg.devDependencies) {
if(taskName.substring(0, 6) == 'grunt-') {
grunt.loadNpmTasks(taskName);
}
}
//deploy task, enter 'grunt deploy'
grunt.registerTask('deploy', ['clean', 'cssmin']);
//default task, enter 'grunt'
grunt.registerTask('default', ['watch', 'concat', 'compass', 'uglify']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment