imagemin / imagemin

[Unmaintained] Minify images seamlessly

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

error on svg

Stephan-Pe opened this issue · comments

Everything works fine until any .svg appears.

[16:13:24] 'imageMin' errored after 850 ms
[16:13:24] Error in plugin "gulp-imagemin"
Message:
Plugin name should be specified
Details:
fileName: C:\Projects\gulp-ecma6\src\img\background_mobile.svg
domainEmitter: [object Object]
domainThrown: false
I've also tried the recommended setup

imagemin.gifsicle({interlaced: true}),
imagemin.mozjpeg({quality: 75, progressive: true}),
imagemin.optipng({optimizationLevel: 5}),
imagemin.svgo({
	plugins: [
		{removeViewBox: true},
		{cleanupIDs: false}
	]
})

I had no problems with my previous setup using module.exports and gulp-imagemin@7.1.0

Device name LAPTOP-NMN2AKOU
Processor Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz 2.59 GHz
Installed RAM 64.0 GB (63.8 GB usable)
Device ID 0723A001-ACAF-4D82-9E3C-3425B4B9C557
Product ID 00330-50000-00000-AAOEM
System type 64-bit operating system, x64-based processor
Pen and touch No pen or touch input is available for this display

Edition Windows 11 Pro
Version 22H2
Installed on ‎9/‎28/‎2022
OS build 22621.1194
Serial number R90XVZNR
Experience Windows Feature Experience Pack 1000.22638.1000.0

package
gulp

found solution:

got the following error when i wrapped the pipe into try catch block

node:internal/process/promises:288
triggerUncaughtException(err, true /_ fromPromise _/);
^
PluginError: Plugin name should be specified
at resolvePluginConfig (C:\Projects\gulp-ecma6\node_modules\svgo\lib\svgo\config.js:113:13)
at Array.map (<anonymous>)
at optimize (C:\Projects\gulp-ecma6\node_modules\svgo\lib\svgo.js:50:37)
at optimize (C:\Projects\gulp-ecma6\node_modules\svgo\lib\svgo-node.js:97:10)
at C:\Projects\gulp-ecma6\node_modules\imagemin-svgo\index.js:16:17
at file:///C:/Projects/gulp-ecma6/node_modules/p-pipe/index.js:10:25.......

so I took the options out of the plugins array like this

const isProd = process.env.NODE_ENV === "prod";
const { dest } = gulp;
const imgSource = "src/img/**/.";
async function imageMin() {
try {
return gulp.src([imgSource])
.pipe(gulpIf(isProd, imagemin([
gifsicle({ interlaced: true }),
mozjpeg({ quality: 75, progressive: true }),
optipng({ optimizationLevel: 5 }),
svgo({
removeViewBox: true,
cleanupIDs: false
})
])))
.pipe(dest("docs/img/"));
} catch (error) {
console.log(error);
}

}

export default imageMin;

now everything works like acspected

[14:44:22] Finished 'processJson' after 2.68 s
[14:44:23] asset main.js 2.42 KiB [emitted] [minimized] (name: main)

webpack 5.75.0 compiled successfully
[14:44:23] Finished 'processJS' after 3.9 s
[14:44:23] Finished 'default' after 3.92 s
[14:44:24] gulp-imagemin: Minified 17 images (saved 424 kB - 42.6%)