Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
gulp.task('images', 'Optimize images', () =>{
return utils.plumbedSrc(
config.images.src
)
// Display the files in the stream
//.pipe(debug({title: 'Stream contents:', minimal: true}))
// Minify and cache
.pipe(cache(imageMin({
progressive: true,
interlaced: true
})))
// Output files
.pipe(gulp.dest(config.images.dest))
// Task result
.pipe(size({
title: 'images'
}));
});
gulp.task('imagemin', () => {
return gulp.src(path.join(target, '**/.{gif,png,jpg,jpeg,bmp,svg}'))
.pipe(imagemin([
imagemin.gifsicle({ interlaced: true }),
imagemin.jpegtran({ progressive: true }),
imagemin.optipng({ optimizationLevel: 7 }),
imagemin.svgo({ plugins: [{ removeViewBox: true }] })
], {
verbose: true
}))
// .pipe(plugins.changed(dest))
.pipe(gulp.dest(dest));
});
function img() {
return src(`${srcDir}/**/*.{png,jpe?g,gif,svg}`)
.pipe(
cache(
imagemin([
imagemin.gifsicle({ interlaced: true }),
imagemin.jpegtran({ progressive: true }),
imagemin.optipng({ optimizationLevel: 4 }),
imagemin.svgo({
plugins: [
{ removeDimensions: true }, // 如果有 viewbox 则不需要 width 和 height
],
}),
])
)
)
.pipe(
dest(file => {
return file.base; // 压缩到原目录
})
);
}
gulp.task('images', function() {
return gulp
.src(path.join(config.build.source, config.path.images, '**', '*.*')) // i.e.: public/images/**/*.*
.pipe(
imagemin([
imagemin.gifsicle(config.gifsicle),
imagemin.jpegtran(config.jpegtran),
imagemin.optipng(config.optipng),
imagemin.svgo(config.svgo)
])
)
.pipe(gulp.dest(path.join(config.build.target, config.path.images))) // i.e.: public/images
})
const imgTask = function buildImages() {
return gulp.src('src/images/**/*')
.pipe(imagemin([
imagemin.optipng({ optimizationLevel: 5 }),
]))
.pipe(gulp.dest('dist/images'))
.on('end', () => {
console.log('Successfully compressed images');
});
};
gulp.task('image', () => {
return gulp.src('./src/image/**/*.*')
.pipe(imagemin({
progressive: true
}))
.pipe(gulp.dest(DIST + '/image'))
})
gulp.task('imagemin', () => {
gulp.src(paths.destImg + 'page/**/*.*')
.pipe(imagemin({ optimizationLevel: 3 }))
.pipe(gulp.dest(paths.destImg + 'page/'));
});
return new Promise((resolve) => {
vfs.src(path, getSrcOptions())
.pipe(plumber(handleErros))
.pipe(gulpif(
isProd(),
gulpImagemin()
)
)
.pipe(getDest(vfs))
.on('end', resolve);
});
};
gulp.task('images:site', () => {
return gulp
.src(`${PATHS.source.images.site}/**/*`)
.pipe(imagemin())
.pipe(gulp.dest(PATHS.build.images));
});
gulp.task('minify-and-copy-images-to-build-directory', () => {
return gulp.src(config.images.src)
.pipe(gulpif(global.isProduction, imagemin()))
.pipe(gulp.dest(config.images.dest))
.pipe(gulpif(browserSync.active, browserSync.reload({ stream: true, once: true })));
});