gpt4 book ai didi

gulp - BrowserSync 不刷新 HTML 文件

转载 作者:行者123 更新时间:2023-12-04 18:56:58 25 4
gpt4 key购买 nike

BrowserSync 可以正确刷新我正在修改的任何 PHP 页面,或者 SCSS 或 JS。但是对于 HTML 文件,它不会刷新任何内容。为什么不?

注意我的 gulpfile.js嵌套在它自己的子文件夹中 /gulp/ ,这是它的内容:

var gulp = require('gulp');
var sass = require('gulp-sass');
var browserSync = require('browser-sync').create();
var autoprefixer = require('gulp-autoprefixer');
var plumber = require('gulp-plumber');
var onError = function (err) {
console.log('An error occurred:', gutil.colors.magenta(err.message));
gutil.beep();
this.emit('end');
};

gulp.task('sass', function() {
return gulp.src('../assets/styles/**/*.scss')
.pipe(plumber({ errorHandler: onError }))
.pipe(sass())
.pipe(autoprefixer())
.pipe(gulp.dest('../dist/styles'))
.pipe(browserSync.reload({stream: true}))
});

gulp.task('js', function() {
return gulp.src(['../assets/scripts/*.js'])
.pipe(gulp.dest('../dist/scripts'))
.pipe(browserSync.reload({
stream: true
}))
});

gulp.task('browserSync', function() {
browserSync.init({
proxy: 'http://127.0.0.1/vuejs/',
})
})

gulp.task('watch', ['browserSync','js','sass'], function() {
gulp.watch('../assets/styles/**/*.scss',['sass']);
gulp.watch('../**/**/*.php', browserSync.reload);
gulp.watch('../**/**/*.html', browserSync.reload);
gulp.watch('../assets/scripts/*.js', ['js']);
});

最佳答案

您的“观察”任务过于复杂,也许 gulp 会感到困惑。尝试:

gulp.task('watch', ['browserSync','js','sass'], function() {

// you are already calling reload in your sass and js tasks so remove it here
// plus the array is for tasks, not a function call
// also those 'tasks' would run in parallel - which is not what you want

gulp.watch('../assets/styles/**/*.scss',['sass']);

gulp.watch('../**/**/*.php', browserSync.reload);

// you must be able to simplify the following three lines
// ** will match on zero or more entries so all three of these
// will match '../*.html', so try keeping only the first

// EDIT : try this for html reload

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


// gulp.watch('../**/**/*.html', browserSync.reload);
// gulp.watch('../**/*.html', browserSync.reload);
// gulp.watch('../*.html', browserSync.reload);

// see above
gulp.watch('../assets/scripts/*.js', ['js']);

// a duplicate, remove
// gulp.watch('../*.html', browserSync.reload);
});

关于gulp - BrowserSync 不刷新 HTML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50356730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com