Socket
Socket
Sign inDemoInstall

@hugsmidjan/gulp-images

Package Overview
Dependencies
513
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.1 to 0.2.2

6

CHANGELOG.md

@@ -7,2 +7,8 @@ # Change Log

## 0.2.2
_2022-04-28_
- fix: Task ended before all images had been compressed
## 0.2.0 — 0.2.1

@@ -9,0 +15,0 @@

143

gulp-images.js

@@ -31,81 +31,86 @@ const { src, dest, watch } = require('gulp');

return src(files, { base: opts.src })
.pipe(notifyPipeError())
.pipe(
flatmap((stream, file) => {
var fileParams = file.path.match(
/(---q(\d{1,3}(?:-\d{1,3})?)(?:--d(0))?)\.(png|jpe?g)$/i
);
if (fileParams) {
if (fileParams[4].toLowerCase() === 'png') {
const quality = fileParams[2].split('-').map((val) => parseInt(val) / 100);
if (quality.length === 1) {
quality.push(quality[0]);
return new Promise((resolve, reject) => {
src(files, { base: opts.src })
.pipe(notifyPipeError())
.on('error', reject)
.pipe(
flatmap((stream, file) => {
var fileParams = file.path.match(
/(---q(\d{1,3}(?:-\d{1,3})?)(?:--d(0))?)\.(png|jpe?g)$/i
);
if (fileParams) {
if (fileParams[4].toLowerCase() === 'png') {
const quality = fileParams[2].split('-').map((val) => parseInt(val) / 100);
if (quality.length === 1) {
quality.push(quality[0]);
}
stream = stream.pipe(
imagemin([
pngquant({
speed: 1, // default: `3`
strip: true,
quality, // default `undefined` (i.e. 256 colors)
dithering: !fileParams[3]
? undefined
: fileParams[3] === '0'
? false
: parseInt(fileParams[3]) / 100,
}),
])
);
} else {
stream = stream.pipe(
imagemin([
mozjpeg({
quality: parseInt(fileParams[2]),
progressive: true,
}),
])
);
}
console.info('Lossy compressing', file.relative);
stream = stream.pipe(
imagemin([
pngquant({
speed: 1, // default: `3`
strip: true,
quality, // default `undefined` (i.e. 256 colors)
dithering: !fileParams[3]
? undefined
: fileParams[3] === '0'
? false
: parseInt(fileParams[3]) / 100,
}),
])
rename((path) => {
path.basename = path.basename.slice(0, -fileParams[1].length);
})
);
} else {
} else if (compressExt.test(file.path)) {
const hasKeepIdsSuffix = /---ids.svg$/i.test(file.path);
const svgoRules = {
removeViewBox: false,
removeDimensions: true,
...opts.svgoRules,
};
if (opts.svg_keepIds || hasKeepIdsSuffix) {
svgoRules.cleanupIDs = false;
}
stream = stream.pipe(
imagemin([
mozjpeg({
quality: parseInt(fileParams[2]),
progressive: true,
gifsicle({ interlaced: true }),
mozjpeg({ progressive: true }),
optipng({ optimizationLevel: 4 }),
svgo({
plugins: Object.keys(svgoRules).map((name) => ({
name,
active: svgoRules[name],
})),
}),
])
);
if (hasKeepIdsSuffix) {
stream = stream.pipe(
rename((path) => {
path.basename = path.basename.replace(/---ids$/, '');
})
);
}
}
console.info('Lossy compressing', file.relative);
stream = stream.pipe(
rename((path) => {
path.basename = path.basename.slice(0, -fileParams[1].length);
})
);
} else if (compressExt.test(file.path)) {
const hasKeepIdsSuffix = /---ids.svg$/i.test(file.path);
const svgoRules = {
removeViewBox: false,
removeDimensions: true,
...opts.svgoRules,
};
if (opts.svg_keepIds || hasKeepIdsSuffix) {
svgoRules.cleanupIDs = false;
}
return stream;
})
)
.pipe(dest(opts.dist))
.on('end', resolve);
})
stream = stream.pipe(
imagemin([
gifsicle({ interlaced: true }),
mozjpeg({ progressive: true }),
optipng({ optimizationLevel: 4 }),
svgo({
plugins: Object.keys(svgoRules).map((name) => ({
name,
active: svgoRules[name],
})),
}),
])
);
if (hasKeepIdsSuffix) {
stream = stream.pipe(
rename((path) => {
path.basename = path.basename.replace(/---ids$/, '');
})
);
}
}
return stream;
})
)
.pipe(dest(opts.dist));
});

@@ -112,0 +117,0 @@ const compressTask = () => compress(prefixGlobs(opts.glob, opts.src));

{
"name": "@hugsmidjan/gulp-images",
"version": "0.2.1",
"version": "0.2.2",
"description": "Image minification gulp task",

@@ -5,0 +5,0 @@ "main": "gulp-images.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc