Skip to content

Instantly share code, notes, and snippets.

@danieldevine
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save danieldevine/759ae040a6faf637c398 to your computer and use it in GitHub Desktop.

Select an option

Save danieldevine/759ae040a6faf637c398 to your computer and use it in GitHub Desktop.
Gruntfile for image production.
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
imagemin: {
dynamic: {
files: [{
expand: true,
cwd: 'img/raw',
src: ['*.{png,jpg,gif}'],
dest: 'img/build/'
}]
}
},
copy: {
main: {
files: [{
expand: true,
flatten: true,
src: ['img/raw/*'],
dest: 'img/store'
}, ],
},
},
clean: ['img/raw/*'],
watch: {
options: {
livereload: false,
},
images: {
files: ['img/raw/*.{png,jpg,gif}'],
tasks: ['imagemin', 'copy', 'clean'],
options: {
spawn: false,
},
}
},
});
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['imagemin', 'copy', 'clean', 'watch']);
};
@danieldevine
Copy link
Copy Markdown
Author

Based on this file structure:

img
└── build
└── raw
└── store

Images are saved to img/raw in the first instance where they are minified and sent to img/build (from where they are served). An unaltered copy is made of each image in img/raw and sent to img/store for preservation and then deleted from img/raw to speed up the grunt build as you work.

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