gpt4 book ai didi

Gulp 4 browserSync 重新加载

转载 作者:行者123 更新时间:2023-12-05 08:52:59 26 4
gpt4 key购买 nike

我在使用 browserSync 时遇到问题,在尝试了几种不同的方法后我无法重新加载 do 触发器。 BrowserSync 本身已启动并正在运行,但当我手动重新加载时没有任何反应,我必须打开一个新选项卡才能看到任何更改。我不是很了解 gulp 4,而且我看过的所有资源似乎都在使用与我完全不同的方法。如有任何帮助,我们将不胜感激。请随时提出任何问题。

enter image description here

var gulp = require('gulp');
var sass = require('gulp-sass');
var concatcss = require('gulp-concat');
var concatjs = require('gulp-concat');
var uglifycss = require('gulp-uglifycss');
var reload = require('browser-sync').reload();
var nunjucks = require('gulp-nunjucks-render');
var browserSync = require('browser-sync').create();


sass.compiler = require('node-sass');

gulp.task('sass', function () {
return gulp.src('./Edit/sass/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./Edit/css'));
});

gulp.task('concatcss', function() {
return gulp.src('./Edit/css/*.css')
.pipe(concatcss('style.css'))
.pipe(gulp.dest('./Edit/css/concated/'));
});

gulp.task('concatjs', function() {
return gulp.src('./Edit/java-script/*.js')
.pipe(concatjs('scripts.js'))
.pipe(gulp.dest('./Upload/js/'));
});

gulp.task('css', function () {
return gulp.src('./Edit/css/concated/*.css')
.pipe(uglifycss({
"maxLineLen": 80,
"uglyComments": true
}))
.pipe(gulp.dest('./upload/css'));
});


gulp.task('browserSync', function() {

browserSync.init({
server: {
baseDir: "./Upload/"
}
});

});


gulp.task('run',gulp.parallel('browserSync', gulp.series('sass','concatcss','concatjs','css')));

gulp.task('watch', function(){
gulp.watch('./Edit/sass/*.scss',gulp.series('sass'));
gulp.watch('./Edit/css/*.css',gulp.series('concatcss'));
gulp.watch('./Edit/java-script/*.js',gulp.series('concatjs')); // maybe put extra task in all gulp series for browser sync
gulp.watch('./Edit/css/concated/*.css', gulp.series('css'));

});

gulp.task('default', gulp.parallel('watch', 'run'));

最佳答案

对于在这里遇到麻烦的其他人,我的解决方案是将此 .on('change', browserSync.relod) 添加到所需 watch 的末尾。

gulp.task('watch', function(){
gulp.watch('./Edit/sass/*.scss',gulp.series('sass'));
gulp.watch('./Edit/css/*.css',gulp.series('concatcss'));
gulp.watch('./Edit/java-script/*.js',gulp.series('concatjs')); // maybe put extra task in all gulp series for browser sync
gulp.watch('./Edit/css/concated/*.css', gulp.series('css'));
gulp.watch('./Upload/css/*.css').on('change', browserSync.reload);
gulp.watch('./Upload/js/*.js').on('change', browserSync.reload);

});

关于Gulp 4 browserSync 重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54928120/

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