Npm Gulp jekyll浏览器同步重建循环

Npm Gulp jekyll浏览器同步重建循环,npm,gulp,jekyll,reload,browser-sync,Npm,Gulp,Jekyll,Reload,Browser Sync,我在我的Jekyll项目中使用了一个Gulp脚本,同时使用了浏览器同步和一些其他插件(用于缩小/concat JS/Sass和缩小图像和svg) 从几天前开始(我不确定是什么原因导致的,使用我以前的gulp脚本没有帮助),每次保存HTML或JS文件时都会导致2-15次重新加载循环 这将在终端中以以下方式返回: [00:51:47] Finished 'jekyll-build' after 850 ms [00:51:47] Starting 'jekyll-rebuild'... [BS] R

我在我的Jekyll项目中使用了一个Gulp脚本,同时使用了浏览器同步和一些其他插件(用于缩小/concat JS/Sass和缩小图像和svg)

从几天前开始(我不确定是什么原因导致的,使用我以前的gulp脚本没有帮助),每次保存HTML或JS文件时都会导致2-15次重新加载循环

这将在终端中以以下方式返回:

[00:51:47] Finished 'jekyll-build' after 850 ms
[00:51:47] Starting 'jekyll-rebuild'...
[BS] Reloading Browsers...
[00:51:47] Finished 'jekyll-rebuild' after 241 μs
[00:51:47] Starting 'jekyll-build'...
      Generating... 
                    done in 0.188 seconds.
 Auto-regeneration: disabled. Use --watch to enable.
[00:51:48] Finished 'jekyll-build' after 881 ms
[00:51:48] Starting 'jekyll-rebuild'...
[BS] Reloading Browsers...
[00:51:48] Finished 'jekyll-rebuild' after 480 μs
[00:51:48] Starting 'jekyll-build'...
      Generating... 
                    done in 0.251 seconds.
 Auto-regeneration: disabled. Use --watch to enable.
[00:51:49] Finished 'jekyll-build' after 826 ms
[00:51:49] Starting 'jekyll-rebuild'...
[BS] Reloading Browsers...
[00:51:49] Finished 'jekyll-rebuild' after 942 μs
我的Gulpfile如下所示。很抱歉在这里粘贴了这么多代码

/**
 * Build the Jekyll Site
 */
gulp.task('jekyll-build', function (done) {
    browserSync.notify(messages.jekyllBuild);
    return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
        .on('close', done);
});

/**
 * Rebuild Jekyll & do page reload
 */
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
    browserSync.reload();
});

/**
 * Wait for jekyll-build, then launch the Server
 */
gulp.task('browser-sync', ['sass', 'jekyll-build', 'jekyll-rebuild', 'imagemin', 'svgmin'], function() {
    browserSync({
        server: {
            baseDir: '_site'
        }
    });
});

/**
 * Compile files from _scss into both _site/css (for live injecting) and site (for future jekyll builds)
 */
gulp.task('sass', function () {
    return gulp.src('_scss/main.scss')
        .pipe(sass({
            includePaths: ['scss'],
            onError: browserSync.notify
        }))
        .pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
        .pipe(gulp.dest('_site/css'))
        .pipe(browserSync.reload({stream:true}))
        .pipe(gulp.dest('css'))
        .pipe(rename({
            extname: ".min.css"
        }))
        .pipe(uglifycss())
        .pipe(gulp.dest('css'))
        .pipe(gulp.dest('_site/css'));
});

/** optimize images **/

gulp.task('imagemin', function() {
    return gulp.src('assets/img/*')
        .pipe(imagemin({
            progressive: true,
            svgoPlugins: [{removeViewBox: false}],
            use: [pngquant()]
        }))
        .pipe(gulp.dest('./_site/assets/img'))
        .pipe(browserSync.reload({stream:true}));
});

gulp.task('svgmin', function() {
    return gulp.src('assets/svg/*.svg')
        .pipe(svgmin())
        .pipe(gulp.dest('./_site/assets/svg'));
});

gulp.task('scripts', function() {
    return gulp.src([
        '***scripts***' //removed for readability
        ])
        .pipe(include())
        .pipe(plumber({
            errorHandler: function(err){
                notify('JS compile error: ' + err);
            }
        }))
        .pipe(concat('main.js'))
        .pipe(gulp.dest('javascript'))
        .pipe(rename({
            extname: ".min.js"
        }))
        .pipe(uglify())
        .pipe(gulp.dest('javascript'))
        .pipe(browserSync.reload({stream:true}))
        .pipe(notify('JS Compiled'));
});

/** Lint JS **/

gulp.task('lint', function() {
    return gulp.src('javascript/app/*.js')
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

/**
 * Watch scss files for changes & recompile
 * Watch html/md files, run jekyll & reload BrowserSync
 */
gulp.task('watch', function () {
    gulp.watch('_scss/**/**/**/*.scss', ['sass']);
    gulp.watch('assets/img/*', ['imagemin']);
    gulp.watch('assets/svg/*', ['svgmin']);
    gulp.watch('javascript/app/*.js', ['lint', 'scripts']);
    gulp.watch(['*.html', '**/*.html', 'javascript/main.js', '_layouts/*.html', '_includes/**/**/*.html'], ['jekyll-rebuild']);
});

/**
 * Default task, running just `gulp` will compile the sass,
 * compile the jekyll site, launch BrowserSync & watch files.
 */
gulp.task('default', ['browser-sync', 'watch']);

有没有人看到可能是什么原因造成的

我认为您的手表功能线太宽:
gulp.watch(['*.html','***/.html',javascript/main.js','.\u layouts/*.html','.\u includes/***/.html',['jekyll-rebuild'])

第二个-
“***.html”
我想是看到了任何子文件夹,其中包括_site文件夹,因此它看到了所有的更改,并陷入了一个循环。你改变一个文件,它会重新生成,_站点文件夹被转储,它会看到,重新生成,等等

编辑到排除的站点文件夹
如果您有很多子文件夹,并且希望将它们包含在
***.html
中,请尝试通过添加
'排除_站点目录_site/***'
添加到列表中

另外,请记住,您指定的是.html,它不会拾取任何标记文件

解决这个问题导致了这一点-我想这将是我的新手表(我没有理由不看所有文件,其他人可能不想要这个):

gulp.watch(['***/*.'、'!_site/***'、'!node_modules/***'、'!.sass cache/***']、['jekyll-rebuild'])

第一部分似乎监视所有内容,第二部分排除站点文件夹和其中的所有内容,然后节点_模块和.sass缓存也是如此。。到目前为止,我还无法打破它,这比我所拥有的要简单得多:

gulp.watch(['./*', '_layouts/*', '_videos/*', 'order-online/*', '_includes/*', '_posts/*', '_sass/*', 'css/*', 'services/*', '_data/*' ], ['jekyll-rebuild']);

谢谢你的回答。我想你在用正确的方式感动我。如何确保不包含_站点文件夹?我有很多子文件夹,其中包含单独的index.html文件。我当然可以单独指向文件夹,但排除_站点会更干净。我知道我可以单独指向我的所有文件夹,而不是使用
***.html
,它确实停止了循环!如果你知道一种排除_站点文件夹的方法,那就太好了,否则我明天会接受你的答案。试着用!以排除该子文件夹。我将编辑我的答案,将其包括在内。