3

grunt-imagemin が 2 つの異なるフォルダーの画像を取得するように設定しようとしています。

私は2つのフォルダを持っています:

  1. 画像 - ユーザー
  2. 画像 - 製品。

私の考えは、grunt-imagemin を grunt-watch で使用し、このタスクを手動で行うことを避けることです。トラフィックの多い Web サイトを持っていますが、これを手動で行うと、CPU が崩壊します。ユーザーが画像をアップロードしている間にこれを行うとよいと思います。

私の gruntfile.js は次のとおりです。

grunt.initConfig({
    uglify: {
        files: { 
            src: 'client/js/views/*.js',  // source files mask
            dest: 'client/js/views/min/',    // destination folder
            expand: true,    // allow dynamic building
            flatten: true,   // remove all unnecessary nesting
            ext: '.js'   // replace .js to .min.js
        }
    },
    watch: {
        js:  { files: 'client/js/views/*.js', tasks: [ 'uglify' ] },
    },
    imagemin: {
        dist: {
            options: {
                optimizationLevel: 7,
                progressive: 5
            },
            files: [{
                expand: true,
                cwd: 'client/img/images-users',
                src: '**/*.{gif,GIF,jpg,JPG,png,PNG}',
                dest: 'client/img/images-users-compressed/'
            }]
        }
    }
});
// load plugins
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-newer');

// register at least this one task
grunt.registerTask('default', ['watch']);
grunt.registerTask('resize', ['newer:imagemin']);

ありがとう。

4

1 に答える 1