简体   繁体   English

Gulp w / Browsersync引导,但没有页面重新加载

[英]Gulp w/Browsersync Boots but no page reload

So I seem to have gulp working with browsersync. 所以我似乎在与浏览器同步工作。 When I start gulp it opens my browser and gives me the following: 当我启动gulp时,它将打开我的浏览器并提供以下内容:

[13:01:41] Using gulpfile D:\Test\gulpfile.js
[13:01:41] Starting 'browser-sync'...
[13:01:41] Finished 'browser-sync' after 46 ms
[13:01:41] Starting 'default'...
[13:01:41] Finished 'default' after 12 µs
[BS] Access URLs:
 -------------------------------------
       Local: http://localhost:3000
    External: http://10.127.127.1:3000
 -------------------------------------
      UI: http://localhost:3001
  UI External: http://10.127.127.1:3001
 -------------------------------------
[BS] Serving files from: ./

Here is my gulpfile 这是我的gulpfile

var gulp = require('gulp');
var browserSync = require('browser-sync').create();


// Static server
gulp.task('browser-sync', function() {
   browserSync.init({
        server: {
            baseDir: "./"
        }
    });
 });

gulp.task('default', ['browser-sync']);

I would it to just watch all the files in my project and reload when there is a change. 我希望仅查看项目中的所有文件,然后在发生更改时重新加载。

Try to modify your task (just add one line) 尝试修改您的任务(只需添加一行)

gulp.task('browser-sync', function() {
    browserSync.init({
        server: {
            baseDir: "./"
        }
    });
    gulp.watch("**/*").on('change', browserSync.reload); // add this line 
});

or maybe you can try my gulp configuration https://github.com/infernalmaster/gulp-happy-starter (it has many code examples inside) 或者也许您可以尝试我的gulp配置https://github.com/infernalmaster/gulp-happy-starter (里面有很多代码示例)

You can try making and array after browserSync.init : 您可以在browserSync.init之后尝试制作和数组:

browserSync.init([ "./assets/styles/**/*.css" , "./*.html" ],{
    server: {
        baseDir: "./"
    }
});

Add your file paths in the array and after that just watch for changes: 在数组中添加文件路径,然后注意更改:

gulp.watch("*.css").on("change", browserSync.reload));
gulp.watch("*.html").on("change", browserSync.reload));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM