我正在模仿John Papa关于Gulp的杰出的Pluralsight课程的代码。
当我使用John的课程中显示的代码时:
.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore())
我在第3行代码上收到错误:
TypeError: Object #<StreamFilter> has no method 'restore'
当我使用gulp-filter
的自述文件中显示的代码时.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore)
我收到一个错误,它无法管道到未定义。
根据我在网上找到的内容,这两种模式都适用于其他模式。关于为什么会发生这种情况的任何线索?
这是整个任务,如果这有帮助,并且控制台日志记录表明在过滤器恢复调用之前一切正常。
如果有帮助,这是整个任务:
gulp.task('build-dist', ['inject', 'templatecache'], function() {
log('Building the distribution files in the /dist folder');
var assets = $.useref.assets({searchPath: './'});
var templateCache = config.temp + config.templateCache.file;
var jsFilter = $.filter('**/*.js');
return gulp
.src(config.index)
.pipe($.plumber({errorHandler: onError}))
.pipe($.inject(gulp.src(templateCache, {read: false}), {
starttag: '<!-- inject:templates:js -->'
}))
.pipe(assets)
.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore())
.pipe(assets.restore())
.pipe($.useref())
.pipe(gulp.dest(config.dist));
});
答案 0 :(得分:11)
restore
的工作方式在gulp-filter的2.x和3.x版本之间发生了变化。
您似乎正在使用3.x分支,因此为了使用restore
,您必须在定义过滤器时将restore
选项设置为true
:< / p>
var jsFilter = $.filter('**/*.js', {restore: true});
然后你就可以了
.pipe(jsFilter.restore)
有关更多信息,请查看文档的此部分以获取最新版本的gulp-filter:
https://github.com/sindresorhus/gulp-filter/tree/v3.0.1#restoring-filtered-files