gruntjs - How can I make Grunt.js imagemin to track *any* folder and possibly store images in one place? -
i'm relatively new grunt.js, setting quiet easy, have 2 issues: 1) first, how track any folder inside given sources folder? example, images folder may contain images, folders images , folders folders images etc. 2) there way watch images in it's primary (build) folder? without forever loop...
here's current config:
module.exports = function(grunt) { grunt.initconfig({ jsdir: 'sources/js/', jsdistdir: 'public/js/', cssdir: 'sources/css/', cssdistdir: 'public/css/', concat: { js: { src: ['<%=jsdir%>*.js'], dest: '<%=jsdistdir%>javascript.js' }, css: { src: ['<%=cssdir%>*.css'], dest: '<%=cssdistdir%>styles.css' } }, min: { dist: { src: ['<%= concat.js.dest %>'], dest: '<%=jsdistdir%>javascript.js' } }, cssmin: { dist: { src: ['<%= concat.css.dest %>'], dest: '<%=cssdistdir%>styles.css' } }, imagemin: { dynamic: { files: [{ expand: true, cwd: 'sources/images/', src: ['**/*.{png,jpg,gif}'], dest: 'public/images/' }] } }, watch: { min: { files: ['<%=jsdir%>*.js'], tasks: ['concat:js', 'min'] }, cssmin: { files: ['<%=cssdir%>*.css'], tasks: ['concat:css', 'cssmin'] }, imagemin: { files: ['sources/images/**/*.{png,jpg,gif}'], tasks: ['imagemin'] } } }); grunt.loadnpmtasks('grunt-contrib-concat'); grunt.loadnpmtasks('grunt-yui-compressor'); grunt.loadnpmtasks('grunt-contrib-imagemin'); grunt.loadnpmtasks('grunt-contrib-watch'); grunt.registertask('default', [ 'concat', 'min', 'cssmin', 'imagemin', 'watch' ]); };
thanks!
question 1):
the expression **/*
this. (see imagemin > dynamic > files > src). inside concat section src: ['<%=jsdir%>**/*.js'],
question 2): use a watch task:
install: npm install grunt-contrib-watch --save-dev
(--save-dev
means write dependency package.json file)
configuration in gruntfile.js:
(function () { 'use strict'; }()); module.exports = function(grunt) { require('load-grunt-tasks')(grunt); // auto load grunt tasks var globalconfig = { jspath: 'js/', csspath: 'css/', scsspath: 'scss/', }; grunt.initconfig({ globalconfig: globalconfig, pkg: grunt.file.readjson('package.json'), concat: { // conf goes here }, // other tasks go here imagemin: { // conf goes here }, watch: { dev:{ files: ['<%= globalconfig.jspath %>_*.js', '<%= globalconfig.scsspath %>**/*.scss'], tasks: ['concat','imagemin', 'yourothertasks'] } } }); grunt.registertask('default', ['concat', 'imagemin', 'yourothertasks', 'watch:dev']); };
Comments
Post a Comment