Open replete opened 2 years ago
The problem is resolved by importing the imagemin modules directly after adding the packages to the local project.
I guess the fix is to either update the docs, or move the imagemin from optionalDependencies
into devDependencies
?
"devDependencies": {
"browser-sync": "^2.27.5",
"del": "^6.0.0",
"fancy-log": "^1.3.3",
"gulp": "^4.0.2",
"gulp-imagemin": "^8.0.0",
"gulp-sass": "^5.0.0",
+ "imagemin": "^8.0.1",
+ "imagemin-mozjpeg": "^9.0.0",
+ "imagemin-optipng": "^8.0.0",
+ "imagemin-svgo": "^10.0.0",
"sass": "^1.42.1"
}
import gulpSass from 'gulp-sass';
import dartSass from 'sass';
import del from 'del';
import browserSync from 'browser-sync';
import imagemin from 'gulp-imagemin';
+import imageminOptipng from 'imagemin-optipng';
+import imageminSvgo from 'imagemin-svgo';
+import imageminMozjpeg from 'imagemin-svgo';
import fancyLog from 'fancy-log';
function images() {
return gulp.src(paths.images.source, {since: gulp.lastRun(images)})
+ .pipe(imagemin([
+ imageminOptipng({ optimizationLevel: 5 }),
+ imageminSvgo({
+ plugins: [
+ { removeViewBox: true },
+ { cleanupIDs: false }
+ ]
+ }),
+ imageminMozjpeg({ quality: 75, progressive: false })
+ ]))
.pipe(gulp.dest(paths.images.destination));
}
Although this workaround introduces this deprecation warning from imagemin-svgo
. I will raise an issue there and link to this issue.
(node:28326) [DEP0151] DeprecationWarning: No "main" or "exports" field defined in the package.json for /Users/user/dev/frontend-boilerplate/node_modules/imagemin-svgo/ resolving the main entry point "index.js", imported from /Users/user/dev/frontend-boilerplate/gulpfile.js.
Error
Doesn't seem to detect any of the plugins and fails on whatever it hits first, in the above error imagemin.optipng. I've tried adding
imagemin
andimagemin-*
packages to my repository, but this does not help.My implementation appears to match the package expectations. Am I missing something here?
Environment
node v16.10.0 npm 7.24.0 macOS Catalina 10.15.7
gulpfile.js
package.json