2013-12-17 6 views
5

क्या एकाधिक फाइल/फ़ोल्डरों को देखना संभव है लेकिन grunt-contrib-imagemine और grunt-contrib-watch का उपयोग करके केवल एक ही फ़ाइल को अनुकूलित करना संभव है?Grunt imagemin - एकाधिक फाइल/फ़ोल्डरों को एकल फ़ाइल को अनुकूलित करने के लिए देखें?

मैं इस तरह की कोशिश की: (gruntfile का हिस्सा)

imagemin: { 
    dist: { 
    cwd: 'images/modules', 
    files: ['images/modules/**/*.{png,jpg,gif}'], 
    dest: 'images/modules' 
    } 
}, 

watch: { 
    images: { 
     files: ['images/modules/**/*.{png,jpg,gif}'], 
     tasks: ['imagemin'], 
     options: { 
     spawn: false, 
     } 
    } 
} 

grunt.event.on('watch', function(action, filepath, target) { 
    if (grunt.file.isMatch(grunt.config('watch.images.files'), filepath)) { 
     grunt.config('imagemin.dist.src', [filepath]); 
    } 
}); 

लेकिन यह काम नहीं करता। यह लौटाता है:

Running "imagemin:dist" (imagemin) task 
Verifying property imagemin.dist exists in config...OK 
Files: [no src] -> images/modules 
Options: optimizationLevel=7, progressive, pngquant=false 
Options: optimizationLevel=7, progressive, pngquant=false 
Warning: path must be a string 

कोई विचार? धन्यवाद।

उत्तर

7

grunt-contrib-imagemin docs के आधार पर फ़ाइल विशेषता src/dest (key/value) जोड़े का ऑब्जेक्ट लेती है।

files: {       // Dictionary of files 
    'dist/img.png': 'src/img.png', // 'destination': 'source' 
    'dist/img.jpg': 'src/img.jpg', 
    'dist/img.gif': 'src/img.gif' 
    } 

मुझे विश्वास है कि यही कारण है कि आपको त्रुटि मिल रही है।

जो भी आप चाहते हैं उसे करने के लिए, कम से कम मुझे लगता है कि आप चाहते हैं कि मैं नीचे की तरह छविमिन में एक और उपटस्क जोड़ दूंगा।

imagemin: { 
    dist: { 
    files: [{ 
    expand: true,        // Enable dynamic expansion 
    cwd: 'images/modules',      // Src matches are relative to this path 
    src: ['images/modules/**/*.{png,jpg,gif}'],// Actual patterns to match 
    dest:'images/modules'      // Destination path prefix 
    }] 
    }, 
    single: { 
    cwd: 'images/modules', 
    files: 'images/modules/img.png': 'images/modules/img.png', 
    dest: 'images/modules' 
    } 

}, 
watch: { 
    images: { 
     files: ['images/modules/**/*.{png,jpg,gif}'], 
     tasks: ['imagemin:single'], 
     options: { 
     spawn: false, 
     } 
    } 
} 

तो ऊपर घड़ी आदेश सभी फ़ाइलें फ़ाइलें रेगुलर एक्सप्रेशन से मेल और watch मुख्य कार्य के single उपकार्य को पूरा करेगा देखेंगे।

फिर मुझे लगता है कि यह वही है जो आप करना चाहते हैं लेकिन यदि आप इसे और अधिक समझा नहीं सकते?

संबंधित मुद्दे