Gulp-imagemin错误?

sirbozc5  于 2022-12-08  发布在  Gulp
关注(0)|答案(3)|浏览(198)

我第一次使用gulp。在我的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));
});

从我的woking文件夹以$ gulp imagemin运行Git bash时
但它显示以下错误

[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\58_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)

这个问题怎么解决?请帮帮我,有没有人能提供角阀的安装指南,先谢谢了

nkoocmlb

nkoocmlb1#

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))

fivyi3re

fivyi3re2#

npm i gulp-changed --save-dev

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

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

xu3bshqb3#

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

备注

[不使用.pipe(已更改())]

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

相关问题