Ninjanoel
Ninjanoel

Reputation: 2914

GruntJS and imagemin, Is it ok to overwrite 'src'?

I have a grunt script (written by someone else) which is minify'ing images, but the the source and destination are the same folder, which to my mind appears to be overwriting the source with the minified images.

Here is a section from the gruntfile.js

imagemin: {
      options: {
        compress: true
      },
      dist   : {
        files: [
          {
            expand: true,
            cwd   : 'templates',
            src   : ['**/*.{png,jpg,gif}'],
            dest  : 'templates'
          }
        ]
      }
    }

There is also a 'watch' task and 'newer' is in use so files are not reprocessed.

Is this ok? Or should the source and destination always be different? I don't think 'jpg' and 'gif' come in a 'lossless' flavour. I've been told that because the script is using 'newer', it keeps a cache of what it's done that survives a restart.

Upvotes: 0

Views: 324

Answers (1)

suzumakes
suzumakes

Reputation: 770

That sounds like a horrible idea. (I mean that it's written to overwrite the same directory, that's insane!)

You can definitely change src to src: ['large/**/*.{png,jpg,gif}'], and drop the original images there.

newer will still keep track of which files have already been compressed, but you'll still have access to the original high-res images in a separate large folder.

MORE:

Though in my own projects, I have a src folder at the top-level directory for the project, so src/img/**/* is compressed and output to just img. It's a complete split between the source files that all go in a top-level src directory, and production ready is everything but src at the top for static sites, or in a dest/build/whatever directory for more involved projects at the top.

Upvotes: 0

Related Questions