[英]Infinite watch loop with gulp on auto-updated / auto-generated files
我正在尝试使用一些jscs
插件( jscs
, csscomb
)在开发期间即时设置代码样式。
我在gulp进程运行带有format任务的无限循环时遇到问题。
我相信会发生什么:
serve
任务 myfile.scss
由开发人员更新 这是导致此循环的代码段。 (注意:这使用的是Gulp v4)
'use strict'
import { task, parallel, series, src, dest, watch, plugins } from './gulp';
import { startStagingServer } from './servers';
import { solution } from './solution.map';
const path = require('path');
task('serve', parallel(startStagingServer, watchStyles);
function watchStyles() {
watch([ solution.src.styles ], series(formatStyles, compileStyles))
}
function formatStyles(done) {
return src([ solution.src.styles ])
.pipe(plugins.csscomb())
.pipe(dest(solution.src.mount)) // the root of the solution
}
function compileStyles() {
return src([ solution.src.styles ])
.pipe(plugins.sass().on('error', plug.sass.logError))
.pipe(dest(path.join(solution.dest.stage, 'serve')));
}
有谁知道避免这种情况的方法?
避免这种情况的方法是不将修复程序放在观察程序中。 使用2个单独的功能:一个可修复,而另一个则不能。 只看那些不看的。 例:
function taskJscsFix() {
return gulp.src(path.JS)
.pipe(jscs({
configPath: './gulp/.jscsrc',
fix: true
}))
.pipe(gulp.dest(path.SRC.JS));
}
function taskScripts() {
return gulp.src(path.JS)
.pipe(jscs({
configPath: './gulp/.jscsrc'
}))
.pipe(jscs.reporter())
.pipe(gulp.dest(path.DEST.JS));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.