网页为何不自动刷新,始终停留在当前页面?

2026-04-02 13:051阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计493个文字,预计阅读时间需要2分钟。

网页为何不自动刷新,始终停留在当前页面?

Gulpfile.js 脚本配置示例:

javascript// 引入Gulp和所需插件const gulp=require('gulp');const concat=require('gulp-concat');const uglify=require('gulp-uglify');const cleanCSS=require('gulp-clean-css');const del=require('del');

// 合并和压缩JavaScript文件gulp.task('scripts', ()=> { return gulp.src('src/js/**/*.js') .pipe(concat('bundle.js')) .pipe(uglify()) .pipe(gulp.dest('dist/js'));});

// 清理CSS文件gulp.task('styles', ()=> { return gulp.src('src/css/**/*.css') .pipe(cleanCSS()) .pipe(gulp.dest('dist/css'));});

// 清理dist目录gulp.task('clean', ()=> { return del('dist');});

// 默认任务gulp.task('default', gulp.series('clean', 'scripts', 'styles'));

网页为何不自动刷新,始终停留在当前页面?

gulpfile.js如下:

gulpfile.js如下 :

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113/** npm install gulp  gulp-concat gulp-clean-css gulp-fontmin  gulp-uglify gulp-clean gulp-rename run-sequence gulp-htmlmin browser-sync --save-dev **/var gulp = require('gulp');var cOncat= require('gulp-concat'); //合并文件var cleanCss = require('gulp-clean-css'); //压缩cssvar fOntmin= require('gulp-fontmin');var uglify = require('gulp-uglify'); // 压缩 代码var clean = require('gulp-clean');var rename = require('gulp-rename');var runSequence = require('run-sequence');var htmlmin = require('gulp-htmlmin');var browserSync = require("browser-sync").create() // 自动刷新var path = {      dist:'./dist',      fontSrcPath:'./src/css/themes/**/*.*',      cssSrcPath:'./src/css/**.css',      jsSrcPath:'./src/js/**/*.js',      libSrcPath:'./src/lib/*.js',      htmlSrcPath:'./src/**/*.html',      fontDistPath:'./dist/css/themes/',      cssDistPath:'./dist/css/',      jsDistPath:'./dist/js/',      libDistPath:'./dist/lib/',      htmlDistPath:'./dist/',};/*清空文件夹*/gulp.task('clean',function(){      return gulp.src(path.dist,{read: false})           .pipe(clean());});gulp.task('css', function() {  return gulp.src(path.cssSrcPath)    .pipe(concat('all.min.css'))    .pipe(cleanCss({compatibility: 'ie8'}))    .pipe(gulp.dest(path.cssDistPath));});gulp.task('font', function () {    return gulp.src(path.fontSrcPath)        .pipe(fontmin())        .pipe(gulp.dest(path.fontDistPath));});//压缩js代码gulp.task('js', function() {    return gulp.src(path.jsSrcPath)        .pipe(concat('all.min.js')) // 拼接成 一个js        .pipe(uglify()) //压缩 js代码        .pipe(gulp.dest(path.jsDistPath)) //输出到指定目录});gulp.task('jsLib', function() {  return gulp.src(path.libSrcPath)  .pipe(rename({suffix:'.min'}))  .pipe(uglify())  .pipe(gulp.dest(path.libDistPath));});gulp.task('html', function () {    var optiOns= {        removeComments: true,        collapseWhitespace: true,        collapseBooleanAttributes: true,        removeEmptyAttributes: true,        removeScriptTypeAttributes: true,        removeStyleLinkTypeAttributes: true,        minifyJS: true,        minifyCSS: true    };    gulp.src(path.htmlSrcPath)        .pipe(htmlmin(options))        .pipe(gulp.dest(path.htmlDistPath));});//gulp运行的时候gulp.task("default", ['server']);gulp.task('watch',['watch:css','watch:js','watch:html']);gulp.task("init", ['css','font', 'js','jsLib', 'html']);gulp.task('server', ["init","watch"], function() {    browserSync.init({        server: {            baseDir: ["src"]        },        port: 80    });});//监听cssgulp.task("watch:css", function() {    gulp.watch(path.cssSrcPath,['css'], browserSync.reload);});//监听jsgulp.task("watch:js", function() {    gulp.watch(path.jsSrcPath,['js'], browserSync.reload);});//监听htmlgulp.task("watch:html", function() {    gulp.watch(path.htmlSrcPath,['html'], browserSync.reload);});//构建生产gulp.task('build', function () {  runSequence('clean',['css','font', 'js','jsLib', 'html']);});

   

本文共计493个文字,预计阅读时间需要2分钟。

网页为何不自动刷新,始终停留在当前页面?

Gulpfile.js 脚本配置示例:

javascript// 引入Gulp和所需插件const gulp=require('gulp');const concat=require('gulp-concat');const uglify=require('gulp-uglify');const cleanCSS=require('gulp-clean-css');const del=require('del');

// 合并和压缩JavaScript文件gulp.task('scripts', ()=> { return gulp.src('src/js/**/*.js') .pipe(concat('bundle.js')) .pipe(uglify()) .pipe(gulp.dest('dist/js'));});

// 清理CSS文件gulp.task('styles', ()=> { return gulp.src('src/css/**/*.css') .pipe(cleanCSS()) .pipe(gulp.dest('dist/css'));});

// 清理dist目录gulp.task('clean', ()=> { return del('dist');});

// 默认任务gulp.task('default', gulp.series('clean', 'scripts', 'styles'));

网页为何不自动刷新,始终停留在当前页面?

gulpfile.js如下:

gulpfile.js如下 :

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113/** npm install gulp  gulp-concat gulp-clean-css gulp-fontmin  gulp-uglify gulp-clean gulp-rename run-sequence gulp-htmlmin browser-sync --save-dev **/var gulp = require('gulp');var cOncat= require('gulp-concat'); //合并文件var cleanCss = require('gulp-clean-css'); //压缩cssvar fOntmin= require('gulp-fontmin');var uglify = require('gulp-uglify'); // 压缩 代码var clean = require('gulp-clean');var rename = require('gulp-rename');var runSequence = require('run-sequence');var htmlmin = require('gulp-htmlmin');var browserSync = require("browser-sync").create() // 自动刷新var path = {      dist:'./dist',      fontSrcPath:'./src/css/themes/**/*.*',      cssSrcPath:'./src/css/**.css',      jsSrcPath:'./src/js/**/*.js',      libSrcPath:'./src/lib/*.js',      htmlSrcPath:'./src/**/*.html',      fontDistPath:'./dist/css/themes/',      cssDistPath:'./dist/css/',      jsDistPath:'./dist/js/',      libDistPath:'./dist/lib/',      htmlDistPath:'./dist/',};/*清空文件夹*/gulp.task('clean',function(){      return gulp.src(path.dist,{read: false})           .pipe(clean());});gulp.task('css', function() {  return gulp.src(path.cssSrcPath)    .pipe(concat('all.min.css'))    .pipe(cleanCss({compatibility: 'ie8'}))    .pipe(gulp.dest(path.cssDistPath));});gulp.task('font', function () {    return gulp.src(path.fontSrcPath)        .pipe(fontmin())        .pipe(gulp.dest(path.fontDistPath));});//压缩js代码gulp.task('js', function() {    return gulp.src(path.jsSrcPath)        .pipe(concat('all.min.js')) // 拼接成 一个js        .pipe(uglify()) //压缩 js代码        .pipe(gulp.dest(path.jsDistPath)) //输出到指定目录});gulp.task('jsLib', function() {  return gulp.src(path.libSrcPath)  .pipe(rename({suffix:'.min'}))  .pipe(uglify())  .pipe(gulp.dest(path.libDistPath));});gulp.task('html', function () {    var optiOns= {        removeComments: true,        collapseWhitespace: true,        collapseBooleanAttributes: true,        removeEmptyAttributes: true,        removeScriptTypeAttributes: true,        removeStyleLinkTypeAttributes: true,        minifyJS: true,        minifyCSS: true    };    gulp.src(path.htmlSrcPath)        .pipe(htmlmin(options))        .pipe(gulp.dest(path.htmlDistPath));});//gulp运行的时候gulp.task("default", ['server']);gulp.task('watch',['watch:css','watch:js','watch:html']);gulp.task("init", ['css','font', 'js','jsLib', 'html']);gulp.task('server', ["init","watch"], function() {    browserSync.init({        server: {            baseDir: ["src"]        },        port: 80    });});//监听cssgulp.task("watch:css", function() {    gulp.watch(path.cssSrcPath,['css'], browserSync.reload);});//监听jsgulp.task("watch:js", function() {    gulp.watch(path.jsSrcPath,['js'], browserSync.reload);});//监听htmlgulp.task("watch:html", function() {    gulp.watch(path.htmlSrcPath,['html'], browserSync.reload);});//构建生产gulp.task('build', function () {  runSequence('clean',['css','font', 'js','jsLib', 'html']);});