Skip to content

Instantly share code, notes, and snippets.

@tjFogarty
Last active June 18, 2020 15:35
Show Gist options
  • Save tjFogarty/7578728 to your computer and use it in GitHub Desktop.
Save tjFogarty/7578728 to your computer and use it in GitHub Desktop.
Gruntfile that I use for projects
// http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically
module.exports = function(grunt) {
/**
* Saves having to declare each dependency
*/
require( "matchdep" ).filterDev( "grunt-*" ).forEach( grunt.loadNpmTasks );
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
compress: true,
mangle: true,
report: 'min',
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
files: {
"js/all.min.js": ["js/libs/zepto-1.0.1.js", "js/plugins/*.js", "js/main.js"]
}
}
},
sass: {
build: {
files: {
'css/global.min.css': 'css/global.scss'
},
options: {
style: 'expanded'
}
}
},
watch: {
scripts: {
files: ['js/**/*.js', 'js/main.js'],
tasks: ['uglify'],
options: {
spawn: false
}
},
css: {
files: ['css/**/*.scss'],
tasks: ['sass']
},
styles: {
files: ['css/global.min.css'],
tasks: ['autoprefixer', 'cssmin'],
options: {
spawn: false
}
}
},
cssmin: {
minify: {
expand: true,
cwd: 'css/',
src: ['global.min.css'],
dest: 'css/',
ext: '.min.css'
}
},
autoprefixer: {
dist: {
files: {
'css/global.min.css': 'css/global.min.css'
}
}
},
imagemin: {
png: {
options: {
optimizationLevel: 7
},
files: [
{
// Set to true to enable the following options…
expand: true,
// cwd is 'current working directory'
cwd: 'images/',
src: ['*.png'],
// Could also match cwd line above. i.e. project-directory/img/
dest: 'images/',
ext: '.png'
}
]
},
jpg: {
options: {
progressive: true
},
files: [
{
// Set to true to enable the following options…
expand: true,
// cwd is 'current working directory'
cwd: 'images/',
src: ['*.jpg'],
// Could also match cwd. i.e. project-directory/img/
dest: 'images/',
ext: '.jpg'
}
]
}
}
});
};
{
"name": "project-name",
"version": "0.1.0",
"repository": {
"type": "git",
"url": ""
},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-uglify": "~0.2.4",
"grunt-contrib-imagemin": "~0.1.4",
"grunt-contrib-sass": "*",
"grunt-contrib-watch": "~0.5.3",
"matchdep": "*",
"grunt-autoprefixer": "*",
"grunt-contrib-cssmin": "*"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment