Skip to content

Instantly share code, notes, and snippets.

@webgodo
Last active June 17, 2016 15:11
Show Gist options
  • Save webgodo/063d1036afa77404c918 to your computer and use it in GitHub Desktop.
Save webgodo/063d1036afa77404c918 to your computer and use it in GitHub Desktop.
a GruntJS file with `watch` and `uglify` for `css` and `js`
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.initConfig({
uglify: {
my_target: {
files: {
'_/js/script.js': ['_/components/js/*.js']
} // files
} // my_target
} // uglify
,
compass: {
dev: {
options: {
config: 'config.rb'
} // options
} // dev
} // compass
,
watch: {
options: {livereload: true},
scripts: {
files: ['_/components/js/*.js'],
tasks: ['uglify']
} // scripts
,
sass: {
files: ['_/components/sass/*.scss'],
tasks: ['compass:dev']
}
,
html: {
files: ['*.html']
} // html
} // watch
}); // initConfig
grunt.registerTask('default', 'watch');
}; // exports
module.exports = function (grunt) {
var fileBanner = '/*\n <%= pkg.name %> - v<%= pkg.version %> \n ' +//
' Author: Some Kind of People \n ' + //
'\n */\n'
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
options: {
style: 'expanded'
},
dist: {
files:
{
'assets/stylesheets/<%= pkg.name %>.css': 'assets/stylesheets/scss/main.scss',
'assets/vendor/bootstrap/stylesheets/bootstrap.css': 'assets/vendor/bootstrap/stylesheets/bootstrap.scss'
}
}
},
cssmin: {
options: {
banner: fileBanner
},
combine: {
files: {
'assets/stylesheets/<%= pkg.name %>-<%= pkg.version %>.min.css' : ['assets/stylesheets/<%= pkg.name %>.css'],
'assets/vendor/bootstrap/stylesheets/bootstrap.min.css' : ['assets/vendor/bootstrap/stylesheets/bootstrap.css']
}
}
},
watch: {
sass: {
files: ['assets/stylesheets/scss/**/*.scss',
'assets/vendor/bootstrap/stylesheets/**/*.scss'],
tasks: ['sass', 'cssmin']
}
}
});
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['sass', 'cssmin', 'watch']);
};
@webgodo
Copy link
Author

webgodo commented Mar 9, 2016

Sample GruntJS task file for a project which has SASS in it.
This file enables GruntJS to :

  • minify js and css files while it watches file changes on both js and css files.
  • compile sass file to css

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment