0

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.

4

1 に答える 1

0

それは恐ろしい考えのように聞こえます。(つまり、同じディレクトリを上書きするように書かれているということです。それは正気ではありません!)

間違いなく src を変更してsrc: ['large/**/*.{png,jpg,gif}'],、そこに元の画像をドロップできます。

newerどのファイルが既に圧縮されているかは引き続き追跡されますが、別のlargeフォルダーにある元の高解像度画像に引き続きアクセスできます。

もっと:

私自身のプロジェクトでは、プロジェクトsrcの最上位ディレクトリにフォルダーがあるため、src/img/**/*圧縮されてimg. これはソース ファイルを完全に分割したもので、すべて最上位のsrcディレクトリに配置されます。本番用の準備はすべて、src静的サイトの場合は最上位にあり、dest/build/whateverより複雑なプロジェクトの場合は最上位のディレクトリにあります。

于 2016-03-30T13:58:53.710 に答える