sva*_*ssr 14 image image-processing gruntjs
该命令grunt imagemin将以下内容输出到随机文件.
Fatal error: ENOENT, no such file or directory 'app/public/assets/img/epg/recordseries.png'
Run Code Online (Sandbox Code Playgroud)
有趣的是,每次我再次运行命令grunt imagemin时,它会设法处理更多文件,并通过输出有关另一个文件的相同错误而结束.
我正在使用
node v0.10.24
npm 1.3.21
grunt@0.4.2
grunt-contrib-imagemin@0.5.0 node_modules/grunt-contrib-imagemin
+-- filesize@2.0.0
+-- async@0.2.9
+-- chalk@0.4.0 (has-color@0.1.2, ansi-styles@1.0.0, strip-ansi@0.1.1)
+-- image-min@0.1.2 (mkdirp@0.3.5, cache-file@0.1.2, mout@0.7.1, optipng-bin@0.3.1, jpegtran-bin@0.2.3, gifsicle@0.1.4)
Run Code Online (Sandbox Code Playgroud)
这是我的grunt配置imagemin任务:
grunt.config('imagemin', {
options: {
optimizationLevel: 3, // 0 to 7, default =7)
// pngquant: true
},
dynamic: { // Multiple target
files: [{
expand: true, // Enable dynamic expansion
cwd: '<%= context.source %>/assets/img/', // equal to app/wesource/assets/img/
src: ['!**/*-'+arrayToRegexStr(platformIgnoreList)+'**', '**/*.{png,jpg,jpeg,gif}'], // Actual patterns to match //
dest: '<%= context.public %>/assets/img/' // equal to app/public/assets/img/
}]
}
});
Run Code Online (Sandbox Code Playgroud)
Jas*_*ler 11
使用以下命令卸载0.5.0版并返回0.3.0版应恢复以前的功能:
npm uninstall grunt-contrib-imagemin
npm install --save-dev grunt-contrib-imagemin@0.3.0
Run Code Online (Sandbox Code Playgroud)
有一个问题,https://github.com/gruntjs/grunt-contrib-imagemin/issues/140正在进行中,当它被修复时,它应该是安全的升级.
以下解决方案适用于...
这是一个解决方案的 hack,但我发现当它查看目标目录以查看 PNG 图像是否已存在且已优化时,任务失败。当我一遍又一遍地运行该任务时,它会始终完成,每次它都会完成更多图像。我可以通过运行来重复这个问题grunt clean,然后grunt imagemin一遍又一遍。
我看到的错误是:
bash
Fatal error: ENOENT, no such file or directory 'build-production/path-to/some-image.png'
在优化图像之前立即将图像复制到目标目录。这样,复制的检查通过和未优化的图像将被替换为优化后的等效图像。
grunt.task.run(
'copy:imagemin',
'imagemin'
);
Run Code Online (Sandbox Code Playgroud)
copy: {
imagemin: {
files: [{
expand: true,
cwd: '<%= exponential.client.src %>',
src: ['images/**/*.{png,jpg,gif}'],
dest: '<%= exponential.client.buildProduction %>'
}]
}
}
Run Code Online (Sandbox Code Playgroud)
imagemin: {
buildProduction: {
files: [{
expand: true,
cwd: '<%= exponential.client.src %>',
src: ['images/**/*.{png,jpg,gif}'],
dest: '<%= exponential.client.buildProduction %>'
}]
}
}
Run Code Online (Sandbox Code Playgroud)