Gulp-imagemin 错误?

Gulp-imagemin error?

我第一次使用 gulp.In 我的 gulpfile.js 包含

var gulp = require('gulp');
var imagemin = require('gulp-imagemin');
gulp.task('default', function () { console.log('Hello Gulp!') });
gulp.task('imagemin', function() {
   var img_src = 'src/images/**/*', img_dest = 'build/images';

   gulp.src(img_src)
   .pipe(changed(img_dest))
   .pipe(imagemin())
   .pipe(gulp.dest(img_dest));
});

当 运行 Git bash 从我的工作文件夹中作为 $gulpimagemin

但是显示如下错误

[11:35:12] Using gulpfile C:\xampp\htdocs\work\gulpfile.js
[11:35:12] Starting 'imagemin'...
[11:35:12] 'imagemin' errored after 10 ms
[11:35:12] ReferenceError: changed is not defined
    at Gulp.<anonymous> (C:\xampp\htdocs\work\gulpfile.js:8:10)
    at module.exports (C:\xampp\htdocs\work\node_modules\orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (C:\xampp\htdocs\work\node_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (C:\xampp\htdocs\work\node_modules\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (C:\xampp\htdocs\work\node_modules\orchestrator\index.js:134:8)
    at C:\Users_user\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
    at Module.runMain (module.js:607:11)
    at run (bootstrap_node.js:418:7)

我该如何解决这个问题?请帮我。任何人都可以为 angularjs 提供 gulp 安装指南吗?提前致谢

var gulp = require('gulp');
var imagemin = require('gulp-imagemin');
gulp.task('default', function () { console.log('Hello Gulp!') });
gulp.task('imagemin', function() {
   var img_src = 'src/images/**/*', img_dest = 'build/images';

   gulp.src(img_src)
   .pipe(imagemin())
   .pipe(gulp.dest(img_dest));
});

删除不必要的未定义任务changed.pipe(changed(img_dest)).

npm i gulp-changed --save-dev

var gulp = require ('gulp');之后添加这行代码:

var changed = require('gulp-changed');

其他简单的解决方案,如果你想使用 require() 只需更改 版本

备注

[不要使用 .pipe(changed())]

npm install --save-dev gulp-imagemin@7.1.0