Skip to content

Instantly share code, notes, and snippets.

@akrizs
Forked from danalmeida/gruntfile.js
Created May 8, 2018 21:04
Show Gist options
  • Save akrizs/48ed90fbb4afcf22e52649183ecc6b1b to your computer and use it in GitHub Desktop.
Save akrizs/48ed90fbb4afcf22e52649183ecc6b1b to your computer and use it in GitHub Desktop.
boilerplate Grunt configuration
module.exports = function(grunt) {
// 1. All configuration goes here.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
dist: {
options: {
style: 'compressed'
},
files: {
'dist/css/main.min.css': 'scss/main.scss'
}
},
dev: {
options: {
style: 'expanded'
},
files: {
'dist/css/main.css': 'scss/main.scss'
}
}
},
jshint: {
options: {
'-W099': true,
force: true
},
all: [
'js/main.js'
]
},
concat: {
dist: {
files: {
'dist/js/main.js': [
'js/console.js',
'js/main.js'
]
}
}
},
uglify: {
dist: {
files: {
'dist/js/main.min.js': ['dist/js/main.js']
}
}
},
imagemin: {
dynamic: {
files: [{
expand: true,
cwd: 'images/',
src: ['**/*.{png,jpg,gif}'],
dest: 'images_opt/'
}]
}
},
imageoptim: {
pngs: {
options: {
jpegMini: false,
imageAlpha: true,
quitAfter: true
},
src: ['images_opt/*.png']
},
jpgs: {
options: {
jpegMini: true,
imageAlpha: false,
quitAfter: true
},
src: ['images_opt/*.jpg']
}
},
modernizr: {
dist: {
// [REQUIRED] Path to the build you're using for development.
'devFile' : 'js/vendor/modernizr.dev.js',
// [REQUIRED] Path to save out the built file.
'outputFile' : 'dist/js/vendor/modernizr.custom.js',
// Based on default settings on http://modernizr.com/download/
'extra' : {
'shiv' : true,
'printshiv' : false,
'load' : true,
'mq' : false,
'cssclasses' : true
},
// Based on default settings on http://modernizr.com/download/
'extensibility' : {
'addtest' : false,
'prefixed' : false,
'teststyles' : false,
'testprops' : false,
'testallprops' : false,
'hasevents' : false,
'prefixes' : false,
'domprefixes' : false
},
// By default, this task will crawl your project for references to Modernizr tests.
// Set to false to disable.
'parseFiles' : true,
// When parseFiles = true, this task will crawl all *.js, *.css, *.scss files, except files that are in node_modules/.
// You can override this by defining a 'files' array below.
'files' : {
'src': [
'dist/js/*.js',
'dist/css/*.css'
]
}
}
},
watch: {
scripts: {
files: [
'js/*.js'
],
tasks: ['jshint', 'concat', 'uglify'],
options: {
spawn: false,
},
},
css: {
files: [
'scss/*.scss',
'scss/**/*.scss',
'scss/**/**/*.scss'
],
tasks: ['sass'],
options: {
spawn: false,
}
}
}
});
// 3. Where we tell Grunt we plan to use this plug-in.
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-modernizr');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-imageoptim');
grunt.loadNpmTasks('grunt-contrib-watch');
// 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
grunt.registerTask('default', [
'sass',
'jshint',
'concat',
'uglify',
'modernizr'
]);
grunt.registerTask('images', [
'imagemin',
'imageoptim'
]);
};
{
"name": "project_name",
"description": "Project description.",
"version": "0.0.1",
"devDependencies": {
"grunt": "latest",
"grunt-contrib-sass": "latest",
"grunt-contrib-jshint": "latest",
"grunt-contrib-concat": "latest",
"grunt-contrib-uglify": "latest",
"grunt-modernizr": "latest",
"grunt-contrib-imagemin": "latest",
"grunt-imageoptim": "latest",
"grunt-contrib-watch": "latest"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment