0

我第一次使用 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)

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

4

3 回答 3

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

于 2017-02-14T06:43:30.360 回答
0
npm i gulp-changed --save-dev

在后面添加这行代码var gulp = require ('gulp');

var changed = require('gulp-changed');
于 2018-12-16T02:36:15.810 回答
0

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

笔记

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

npm install --save-dev gulp-imagemin@7.1.0
于 2021-10-24T20:55:10.433 回答