[英]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.