简体   繁体   中英

Grunt.js and imagemin - No “imagemin” targets found

I'm trying to teach myself the basics of Grunt.js and I'm finding it anything but intuitive.

I've got it working to a point - I'm able to watch the directory, minifiy JS and compile my compass / sass files.

The problem I'm now having is minifying images using: https://npmjs.org/package/grunt-contrib-imagemin

I keep getting the following error when running $ grunt:

No "imagemin" targets found

I've got my gruntfile here: https://github.com/Tjobbe/sample-grunt-project/blob/master/gruntfile.js and my git repo here: https://github.com/Tjobbe/sample-grunt-project so you can see my directory set up.

Any idea why this isn't working? Ideally I'd want it to continually poll the directory to see if there's any new files, then minify them and put them into the src/img/ directory.

Your imagemin is a subtask of your watch task. If you take it out, it'll work.

Here's part of the Gruntfile.js

        watch: {
        compass: {
            files: ['dev/sass/*.sass'],
            tasks: ['compass:dev']
        },
        js: {
            files: ['dev/js/*.js'],
            tasks: ['uglify']
        }
    },
    compass: {
        dev: {
            options: {
                sassDir: ['dev/sass/'],
                cssDir: ['src/css/'],
                environment: 'development'
            }
        },
        prod: {
            options: {
                sassDir: ['dev/sass/'],
                cssDir: ['src/css/'],
                environment: 'production'
            }
        },
    },
  imagemin: {
    dynamic: {
      files: [{
        expand: true,
        cwd: 'dev/img/',
        src: ['dev/img/*.{png,jpg,gif}'],
        dest: 'src/img/'
      }]
    }
  },
    uglify: {
        all: {
            files: {
                'src/js/min.js': [
                'dev/js/*.js']
                // 'js/*.js']
            }
        },
    },
});

imagemin is a subtask of watch. As of this you need to call it like this watch:imagemin

The same way as you used compass:dev

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM