各位大大们, gulp 的 browser-sync 愁死了。求!!! - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xuecat
V2EX    Angular

各位大大们, gulp 的 browser-sync 愁死了。求!!!

  •  
  •   xuecat 2017-04-10 18:10:09 +08:00 2221 次点击
    这是一个创建于 3105 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我弄的每次修改 js 或 html 文件,浏览器都会刷新页面。而不会重新加载。 这一点都不像网上说的

    以下是我的代码:

     browserSync= require('browser-sync').create(), var htmlSrc = ['app/**/*.html', '!app/index.html', '!app/lib/**/*.html', '!app/lib/*.html']; var jsSrc = ['app/**/*.js', '!app/lib/**/*.js', '!app/assets/**/*.js']; var cssSrc = ['app/assets/**/*.css', '!app/lib/**/*.css']; var imgSrc = ['app/assets/img/*', 'app/assets/img/**/*']; var fOntSrc= ['app/assets/fonts/**/*']; var jsOnSrc= ['app/translate/*.json', 'app/translate/**/*.json']; var libSrc = ['app/lib/**/*']; var indexSrc = 'app/index.html'; var buildPath = 'dist/'; var debugPath = 'app/'; gulp.task('createIndex', function() { return gulp.src(indexSrc) .pipe(replace(/\.js/g, '.min.js')) .pipe(htmlmin({collapseWhitespace: true})) .pipe(gulp.dest(buildPath)) .pipe(browserSync.stream()); }); gulp.task('compressHTML', function() { return gulp.src(htmlSrc) .pipe(htmlmin({collapseWhitespace: true})) .pipe(gulp.dest(buildPath)) .pipe(browserSync.stream()); }); gulp.task('compressJS', function() { var filterIndex = filter(['**/app.config.js', '**/app.module.js', '**/app.route.oclazy.js'], {restore: true}); return gulp.src(jsSrc) .on('error', function(err) {//语法检查,打印错误 console.log('Error: ', err.message); }) .pipe(filterIndex) .pipe(rename({suffix: '.min'})) .pipe(filterIndex.restore) .pipe(uglify())//压缩 .pipe(gulp.dest(buildPath)) .pipe(browserSync.stream()); }); gulp.task('compressCSS', function() { return gulp.src(cssSrc) //.pipe(concat('index.min.css')) 为了使用 oclazyload 不整合 .pipe(minifycss()) .pipe(gulp.dest(buildPath + 'assets')) .pipe(browserSync.stream()); }); gulp.task('compressJSON', function () { return gulp.src(jsonSrc) .pipe(jsonminify()) .pipe(gulp.dest(buildPath + 'translate')) .pipe(browserSync.stream()); }); gulp.task('copyImg', function() { return gulp.src(imgSrc) .pipe(gulp.dest(buildPath + 'assets/img')) .pipe(browserSync.stream()); }); gulp.task('copyLib', function() { return gulp.src(libSrc) .pipe(gulp.dest(buildPath + 'lib')) .pipe(browserSync.stream()); }); gulp.task('copyFont', function() { return gulp.src(fontSrc) .pipe(gulp.dest(buildPath + 'assets/fonts')) .pipe(browserSync.stream()); }); gulp.task('clean', function() { return gulp.src(buildPath) .pipe(clean()); }); gulp.task('startCreate', ['clean'], function() { runSequence('createIndex', ['compressHTML', 'compressJS', 'compressCSS', 'compressJSON'], ['copyLib', 'copyImg', 'copyFont']); }); gulp.task('browserSync', function() { gulp.start('startCreate'); browserSync.init({ server: { baseDir: buildPath } }); gulp.watch(indexSrc, ['createIndex']); gulp.watch(htmlSrc, ['compressHTML']); gulp.watch(jsSrc, ['compressJS']); gulp.watch(cssSrc, ['compressCSS']); gulp.watch(jsonSrc, ['compressJSON']); }); gulp.task('default', ['browserSync']); 
    目前尚无回复
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     909 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 26ms UTC 21:57 PVG 05:57 LAX 14:57 JFK 17:57
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86