grunt-contrib-imagemin output “Fatal error: ENOENT, no such file or directory”

前端 未结 6 1308
盖世英雄少女心
盖世英雄少女心 2021-01-04 04:25

The command grunt imagemin output the following to a random file.

Fatal error: ENOENT, no such file or directory \'app/public/assets/img/epg/rec         


        
6条回答
  •  花落未央
    2021-01-04 05:08

    The following solutions works on...

    • Ubuntu Linux 13.10 x64
    • npm --version = 1.3.11
    • node --version = v0.10.21
    • grunt-contrib-imagemin = 0.5.0

    This is a hack of a solution, but I found the task fails when it looks at the the target directory to see if the PNG image already exists and is optimized. The task would consistently finish when I ran it over and over, each time it would complete a few more images. And I could repeat the problem by running grunt clean, then grunt imagemin over and over.

    The error I saw was:

    bash Fatal error: ENOENT, no such file or directory 'build-production/path-to/some-image.png'

    Solution

    Copy the images to the target dir immediately before optimizing them. This way, the check passes and unoptimized images that are copied are replaced by their optimized equivalent.

    task

    grunt.task.run(
        'copy:imagemin',
        'imagemin'
    );
    

    copy configuration

    copy: {
        imagemin: {
            files: [{
                    expand: true,
                    cwd: '<%= exponential.client.src %>',
                    src: ['images/**/*.{png,jpg,gif}'],
                    dest: '<%= exponential.client.buildProduction %>'
            }]
        }
    }
    

    imagemin configuration

    imagemin: {
        buildProduction: {
            files: [{
                expand: true,
                cwd: '<%= exponential.client.src %>',
                src: ['images/**/*.{png,jpg,gif}'],
                dest: '<%= exponential.client.buildProduction %>'
            }]
        }
    }
    

提交回复
热议问题