Last active
August 29, 2015 14:16
-
-
Save danieldevine/759ae040a6faf637c398 to your computer and use it in GitHub Desktop.
Gruntfile for image production.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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']); | |
| }; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.