2

我在下面运行 Gulp 管道。管道在终端中正常运行,并且图像输出到 /dist 文件夹中。这些图像的文件大小与 /src 完全相同。

import imagemin from "gulp-imagemin";
import imageminJpg from "imagemin-jpeg-recompress";
import imageminPng from "imagemin-pngquant";

 gulp.task('min', function() {
   return gulp.src('site/static/images/*')
   .pipe(imagemin(
     [imageminPng(), imageminJpg()],
   {verbose: true}
   ))
  .pipe(gulp.dest('dist/images'));
 });

终端输出(相关领域)

[00:12:39] Starting 'fonts'...
[00:12:39] Starting 'clean'...
[00:12:39] Starting 'min'...
[00:12:39] Finished 'hugo' after 429 ms
[00:12:39] Finished 'clean' after 30 ms
[00:12:39] gulp-imagemin: ✔ aluminium_services.svg (already optimized)
[00:12:40] gulp-imagemin: ✔ contact-facebook.svg (already optimized)
[00:12:40] gulp-imagemin: ✔ about_background.jpg (saved 296 kB - 61%)
[00:12:40] Finished 'scss' after 1.09 s
[00:12:40] gulp-imagemin: ✔ contact-form-send-icon.svg (already optimized)
[00:12:40] gulp-imagemin: ✔ contact_send.svg (already optimized)
[00:12:40] gulp-imagemin: ✔ dog-marker.png (already optimized)
[00:12:40] gulp-imagemin: ✔ footer-up-arrow.svg (already optimized)
[00:12:40] Finished 'fonts' after 855 ms
[00:12:40] gulp-imagemin: ✔ menu.svg (already optimized)
[00:12:41] gulp-imagemin: ✔ timber_capped.jpg (already optimized)
[00:12:41] gulp-imagemin: ✔ testimonial_joel.jpg (already optimized)
[00:12:41] gulp-imagemin: ✔ timber_retaining_wall.jpg (already optimized)
[00:12:41] gulp-imagemin: ✔ timber_chain.jpg (already optimized)
[00:12:41] gulp-imagemin: ✔ timber_trellis.jpg (already optimized)
[00:12:41] [webpack] Hash: 25ab7c02b4a660acbf18
Version: webpack 4.6.0
Time: 2327ms
Built at: 08/17/2018 12:12:41 AM
Asset     Size  Chunks                    Chunk Names
app.js  565 KiB       0  [emitted]  [big]  app
Entrypoint app [big] = app.js

[00:12:41] Finished 'js' after 2.72 s
[00:12:41] gulp-imagemin: ✔ timber_standard2.jpg (already optimized)
[00:12:42] gulp-imagemin: ✔ landing_hero_background.jpg (saved 2.27 MB - 
71%)
[00:12:42] gulp-imagemin: ✔ slide_ref.jpg (saved 2.41 MB - 77.9%)
[00:12:42] gulp-imagemin: Minified 3 images (saved 4.97 MB - 73.4%)
[00:12:42] Finished 'min' after 3.24 s
[00:12:42] Starting 'server'...
[00:12:42] Finished 'server' after 27 ms
[00:12:42] Starting 'build'...

Total in 120 ms
[00:12:42] Finished 'build' after 173 ms
4

2 回答 2

0

将 gulp-cache 添加到 imagemin 管道,清除 /dist

gulp.task('min', () =>
gulp.src('site/static/images/*')
    .pipe(cache(imagemin(
  [imageminPngquant(), imageminJPG()],
  {verbose: true}
)))
    .pipe(gulp.dest('dist/images'))
);
于 2018-08-17T04:46:36.253 回答
0

正如您在输出中看到的那样,似乎大多数图像已经过优化。

一张经过优化的图像是:landing_hero_background.jpg

[00:12:42] gulp-imagemin: ✔ landing_hero_background.jpg (saved 2.27 MB - 
71%)
  1. 完全删除 dist 文件夹,然后重新构建。

  2. /site/static/images在和中比较这个特定的图像dist/images

于 2018-08-16T13:13:11.653 回答