Grunt watch does not detect new images

Asked

Viewed 65 times

1

Hello, I’m trying to make Grunt watch a directory and when a new image is added, it compresses it. However, it does not perform anything when adding images in the directory, it works perfectly for my Less and js.

package json.

"devDependencies": {
    "grunt": "^1.0.1",
    "grunt-cli": "^1.2.0",
    "grunt-contrib-concat": "^1.0.1",
    "grunt-contrib-copy": "^1.0.0",
    "grunt-contrib-cssmin": "^2.2.1",
    "grunt-contrib-imagemin": "^2.0.1",
    "grunt-contrib-less": "^1.4.1",
    "grunt-contrib-uglify": "^3.0.1",
    "grunt-contrib-watch": "^1.0.0",
    "grunt-newer": "^1.3.0"
  },

gruntfile.js

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    imagemin: {
        dynamic: {
            options: {
                optimizationLevel: 3,
                svgoPlugins: [{removeViewBox: false}]
            },
            files: [{
                expand: true,
                cwd: 'src/img/',
                src: '*.{png,jpg,jpeg,gif,svg}',
                dest: 'dist/img'
            }]
        }
    },

    watch: {
        img: {
            files: 'src/img/*.{png,jpg,jpeg,gif,svg}',
            tasks: 'dist-img-newer'
        }
    }
});

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-newer');

grunt.registerTask('dist-img-newer', ['newer:imagemin']);
  • changes the files: src/img/.{png,jpg,jpeg,gif,svg}' for files: 'src/img/*' just to check if the watch starts listening to the changes understood?

  • You have that repository on Github?

  • How is the folder structure of your project?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.