Javascript Gulp-将参数传递给内部函数
我有一个通过数组循环的手表任务。数组中的字符串用于获取要监视的不同文件路径。这是带手表功能的线路。on函数查找这些文件中的更改。如果有更改,将调用一个新函数,该函数将开始编译sass文件Javascript Gulp-将参数传递给内部函数,javascript,parameter-passing,gulp,gulp-watch,Javascript,Parameter Passing,Gulp,Gulp Watch,我有一个通过数组循环的手表任务。数组中的字符串用于获取要监视的不同文件路径。这是带手表功能的线路。on函数查找这些文件中的更改。如果有更改,将调用一个新函数,该函数将开始编译sass文件 function setWatchPipe(groupName) { gulp .watch(watchStyles[groupName]) .on('change', function(e, groupName) { console.log(groupName);
function setWatchPipe(groupName) {
gulp
.watch(watchStyles[groupName])
.on('change', function(e, groupName) {
console.log(groupName);
return gulp.src(appFiles.styles.src + groupName)
.pipe($.plumber({ errorHandler: function (error) {}}))
.pipe($.rubySass({
style: sassStyle,
compass: true,
noCache: true
}))
.pipe(isProduction ? $.combineMediaQueries({ log: true }) : _.noop())
.pipe(isProduction ? $.minifyCss({ keepSpecialComments: 1 }) : _.noop())
.pipe($.plumber.stop())
.pipe(gulp.dest(paths.styles.dest))
.pipe($.size({
showFiles: true
}));
});
}
var watchArray = ['base', 'front'];
gulp.task('watch', ['build-styles'], function() {
for(var i = 0; i < watchArray.length; i++)
setWatchPipe(watchArray[i]);
});
函数setWatchPipe(groupName){
吞咽
.watch(watchStyles[groupName])
.on('change',函数(e,groupName){
console.log(groupName);
return gulp.src(appFiles.styles.src+groupName)
.pipe($.plumber({errorHandler:function(error){}}))
.pipe($.rubySass({
风格:时髦,
罗盘:没错,
诺卡奇:是的
}))
.pipe(isProduction?$.combineMediaQueries({log:true}):\u0.noop()
.pipe(isProduction?$.minifyCss({keepSpecialComments:1}):\uu0.noop()
.pipe($.plumber.stop())
.管道(吞咽目标(路径、样式目标))
.管道(美元/尺寸)({
showFiles:true
}));
});
}
var watchArray=['base','front'];
gulp.task('watch',['build-style',function()){
对于(var i=0;i
我的问题是里面的参数“groupName”。监视任务会对更改做出反应,但console.log未定义。我需要从数组中获取字符串的输出,但我不知道如何将变量传递到该位置(需要获取正确的源文件,必须写入)
您好,
Lars尝试使用
函数(e)
而不是函数(e,groupName)
。可能是将变量groupName
设置为undefined
,用于关闭。change
回调只返回一个参数 马安。我试着只写“groupName”,但从不写“e”。就这样。谢谢你,伙计!:)帅哥:)很乐意帮忙。