Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getPngPlugins(quality) {
// If quality is between 0 - 100 use mozjpeg plugin
if (/^([0-9][0-9]?|100)$/.test(quality)) {
return [
imageminPngquant({
quality: quality
})
];
}
if (quality === "perfect") {
return [imageminPngquant({
quality: 100
})];
}
if (quality === "ultra") {
return [imageminPngquant({
quality: 90
})];
}
if (quality === "high") {
return [imageminPngquant({
quality: 80
})];
}
}
if (quality === "high") {
return [imageminPngquant({
quality: 80
})];
}
if (quality === "medium") {
return [imageminPngquant({
quality: 70
})];
}
if (quality === "low") {
return [imageminPngquant({
quality: 60
})];
}
// If we get here this means quality do not match any of our conditions which
// should not happen.
throwNotFoundQualityError();
}
if (/^([0-9][0-9]?|100)$/.test(quality)) {
return [
imageminPngquant({
quality: quality
})
];
}
if (quality === "perfect") {
return [imageminPngquant({
quality: 100
})];
}
if (quality === "ultra") {
return [imageminPngquant({
quality: 90
})];
}
if (quality === "high") {
return [imageminPngquant({
quality: 80
})];
}
if (quality === "medium") {
return [imageminPngquant({
quality: 70
})];
}
const assets = paths.map(async assetPath => {
const asset = await imagemin([assetPath], '', {
plugins: [
imageminPngquant(options.png),
imageminJpegtran(options.jpg),
imageminGifsicle(options.gif),
imageminSvgo(options.svg)
]
});
asset[0].path = assetPath;
return asset[0];
});
}),
$.imagemin.jpegtran(),
$.imagemin.svgo({
plugins: [
{
removeUselessDefs: false
},
{
removeViewBox: false
},
{
cleanupIDs: false
}
]
}),
imageminPngquant()
])
)
)
.pipe(utils.detectConflict())
.pipe(gulp.dest(`${config.get('distDir')}/${config.get('baseDir')}`))
.pipe($.if(config.get('webp'), $.filter('**/*.+(png|jp?(e)g)')))
.pipe(
$.if(
config.get('webp') && !isDev,
$.imagemin([
imageminWebp({
quality: '90',
method: 6
})
])
)
export function images () {
return gulp.src(paths.images.src)
.pipe(plumber(config.plumberConfig))
.pipe(imagemin([
pngquant(),
mozjpeg()
], {
verbose: true
}))
.pipe(gulp.dest(paths.images.dest))
}
$.imagemin.gifsicle({
optimizationLevel: 3
}),
$.imagemin.jpegtran({
progressive: true
}),
$.imagemin.svgo({
plugins: [{
removeUselessDefs: false
}, {
removeViewBox: false
}, {
cleanupIDs: false
}]
}),
imageminPngquant({
quality: '80-90',
speed: 1
})
])))
.pipe(utils.detectConflict())
.pipe(gulp.dest(upath.join(config.distDir, config.basePath)))
.pipe($.if(config.webp, $.filter('**/*.+(png|jp?(e)g)')))
.pipe($.if(config.webp && !isDev, $.imagemin([
imageminWebp({
quality: '90',
method: 6
})
])))
.pipe($.if(config.webp, $.rename({
extname: '.webp'
})))
export function optimizeImages() {
return gulp.src([`${config.src}/images/**/*`, `!${config.src}/images/{sprite,sprite/**}`])
.pipe(newer(`${config.dist}/images`))
.pipe(cache(imagemin({
progressive: true,
interlaced: true,
use: [pngquant()]
})))
.pipe(gulp.dest(`${config.dist}/images`));
}
function images () {
return gulp.src(PATHS.images)
.pipe(gulpif(PRODUCTION,
imagemin([
imageminGifsicle({ interlaced: true, optimizationLevel: 3 }),
imageminMozjpeg({ quality: 80 }),
imageminPngquant({ quality: [0.5, 0.8] }),
imagemin.svgo({ plugins: [{ removeViewBox: true }, { cleanupIDs: false }] })
])))
.pipe(gulp.dest(`${PATHS.dist}/assets`))
}
export function imagesOptimize() {
return gulp
.src([`${configs.paths.src}/img/**/*`, `!${configs.paths.src}/img/{icons,icons/**}`])
.pipe(newer('.cache/img'))
.pipe(
imagemin([
imagemin.gifsicle({ interlaced: true }),
imageminMozjpeg({ progressive: true }),
imageminPngquant({
quality: [0.6, 0.8],
}),
imagemin.svgo({ plugins: [{ removeDimensions: true }] }),
]),
)
.pipe(gulp.dest('.cache/img'))
.on('error', notifierErrorHandler);
}