我在我們的構建過程中添加了watchify
,但我希望提前注意運行,那就是更改的文件通過了我們的linting步驟(使用ESLint
)。在watchify運行之前運行eslint
我想這樣做的:
function runBrowserify(watch){
var babel = babelify.configure({
optional: ['es7.objectRestSpread']
});
var b = browserify({
entries: './app/main.js',
debug: true,
extensions: ['.jsx', '.js'],
cache: {},
packageCache: {},
fullPaths: true
})
.transform(babel);
if(watch) {
// if watch is enable, wrap this bundle inside watchify
b = watchify(b);
b.on('update', function(ids) {
//run the linting step
lint(ids);
//run the watchify bundle step
gutil.log(gutil.colors.blue('watchify'), 'Started');
bundleShare(b);
});
b.on('time', function (time) {
gutil.log(gutil.colors.blue('watchify'), 'Finished', 'after', gutil.colors.magenta(time), gutil.colors.magenta('ms'));
});
}
bundleShare(b);
}
function bundleShare(b) {
b.bundle()
.pipe(source('main.min.js'))
.pipe(gulp.dest('./dist'));
}
function lint(glob) {
return gulp.src(glob)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
}
問題是掉毛的步驟是異步所以也沒有完成捆綁將完成之前(也拋出所以我可能需要使用plumber
阻止它終止watch
步驟)。
那麼在我打電話給bundleShared
之前,我會怎麼做一個先決條件?
你知道嗎? – Loknar
nope。我必須爲他們並排運行,所以我有時會錯過ESLint錯誤 –
我想知道是否也許這可以通過將關閉傳遞給watchify.on('update',func)來完成? https://github.com/substack/watchify我會嘗試一下,讓你知道 –