<i id='qdQ1o'><tr id='qdQ1o'><dt id='qdQ1o'><q id='qdQ1o'><span id='qdQ1o'><b id='qdQ1o'><form id='qdQ1o'><ins id='qdQ1o'></ins><ul id='qdQ1o'></ul><sub id='qdQ1o'></sub></form><legend id='qdQ1o'></legend><bdo id='qdQ1o'><pre id='qdQ1o'><center id='qdQ1o'></center></pre></bdo></b><th id='qdQ1o'></th></span></q></dt></tr></i><div id='qdQ1o'><tfoot id='qdQ1o'></tfoot><dl id='qdQ1o'><fieldset id='qdQ1o'></fieldset></dl></div>

<small id='qdQ1o'></small><noframes id='qdQ1o'>

    1. <tfoot id='qdQ1o'></tfoot>
    2. <legend id='qdQ1o'><style id='qdQ1o'><dir id='qdQ1o'><q id='qdQ1o'></q></dir></style></legend>

      • <bdo id='qdQ1o'></bdo><ul id='qdQ1o'></ul>

      1. 我可以将 gulp livereload 设置为在所有文件编译后运

        时间:2023-05-28

          • <tfoot id='J3FDX'></tfoot>
            <i id='J3FDX'><tr id='J3FDX'><dt id='J3FDX'><q id='J3FDX'><span id='J3FDX'><b id='J3FDX'><form id='J3FDX'><ins id='J3FDX'></ins><ul id='J3FDX'></ul><sub id='J3FDX'></sub></form><legend id='J3FDX'></legend><bdo id='J3FDX'><pre id='J3FDX'><center id='J3FDX'></center></pre></bdo></b><th id='J3FDX'></th></span></q></dt></tr></i><div id='J3FDX'><tfoot id='J3FDX'></tfoot><dl id='J3FDX'><fieldset id='J3FDX'></fieldset></dl></div>

            <small id='J3FDX'></small><noframes id='J3FDX'>

            <legend id='J3FDX'><style id='J3FDX'><dir id='J3FDX'><q id='J3FDX'></q></dir></style></legend>
              <bdo id='J3FDX'></bdo><ul id='J3FDX'></ul>

                <tbody id='J3FDX'></tbody>

                  本文介绍了我可以将 gulp livereload 设置为在所有文件编译后运行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我已经设置了一个 gulp 来使用 Stylus、Jade 和 tiny-lr.我的问题是,当我保存一个玉文件时,它开始编译它们,因此在我当前正在处理的文件被编译之前,实时重新加载会在复制到目标的第一个文件上触发,导致我不得不手动刷新.我已经使用gulp-changed"解决了这个问题,但我似乎无法配置它或其他东西.以前有人遇到过这个问题吗?我正在发布我的 Gulp 文件,以便您查看.

                  I've got a gulp set up to work with Stylus, Jade and tiny-lr. My problem is that when I save one jade file, it start's compiling them all, therefore live reloading fires on the first file copied to the destination, before the file I am working on currently is compiled, resulting in me having to refresh manually. I have fixing this issue using "gulp-changed" but I don't seem to be able to configure it or something. Anyone had this problem before? I am posting my Gulp file so you can take a look.

                  可以在此处找到问题的时间线图:https:///www.dropbox.com/s/3g37oy25s9mq969/jade_compile_frefresh_problem.png?dl=0

                  A timeline diagram of the problem can be found here: https://www.dropbox.com/s/3g37oy25s9mq969/jade_compile_frefresh_problem.png?dl=0

                  感谢任何帮助!

                      'use strict';
                  
                      var gulp = require('gulp');
                      var jade = require('gulp-jade');
                      var gutil = require('gulp-util');
                      var stylus = require('gulp-stylus');
                      var jeet = require('jeet');
                      var nib = require('nib');
                      var uglify = require('gulp-uglify');
                      var lr = require('tiny-lr')();
                      // var mainBowerFiles = require('main-bower-files');
                  
                      // Define sources object
                      var sources = {
                        jade: "jade/**/*.jade",
                        partials: "partials/**/*.jade",
                        stylus: "styl/**/*.styl",
                        scripts: "js/**/*.js"
                      };
                  
                      // Define destinations object
                  
                      var destinations = {
                        html: "dist/",
                        css: "dist/css",
                        js: "dist/js"
                      };
                  
                      // Compile and copy Jade
                      gulp.task("jade", function(event) {
                        return gulp.src(sources.jade)
                        .pipe(jade({
                          pretty: true
                        })).pipe(gulp.dest(destinations.html));
                      });
                  
                      // Compile and copy Stylus
                      gulp.task("stylus", function(event) {
                        return gulp.src(sources.stylus).pipe(stylus({
                          use: [nib(), jeet()],
                          import: [
                            'nib',
                            'jeet'
                          ],
                          style: "compressed"
                        })).pipe(gulp.dest(destinations.css));
                      });
                  
                      // Minify and copy all JavaScript
                      gulp.task('scripts', function() {
                        gulp.src(sources.scripts)
                          .pipe(uglify())
                          .pipe(gulp.dest(destinations.js));
                      });
                  
                      // Consolidate Bower Files and copy to /dist/js/
                      // gulp.task('bower-files', function() {
                      //   return gulp.src(mainBowerFiles(/* options */), {})
                      //     .pipe(gulp.dest(destinations.js));
                      // });
                  
                      // Watch for file changes and execute tasks
                      gulp.task("watch", function() {
                        gulp.watch(sources.jade, ["jade"]);
                        gulp.watch(sources.partials, ["jade"]);
                        gulp.watch(sources.stylus, ["stylus"]);
                        gulp.watch(sources.scripts, ["scripts"]);
                        gulp.watch('dist/**/*', refresh);
                      });
                  
                      // Live Reload
                      gulp.task('serve', function () {
                        var express = require('express');
                        var app = express();
                        app.use(require('connect-livereload')());
                        app.use(express.static(__dirname+'/dist/'));
                        app.listen(4000, '0.0.0.0');
                        lr.listen(35729);
                      });
                  
                      // Define default task
                      gulp.task("default", ["jade", "stylus", "scripts", "serve", "watch"]);
                  
                      // Refresh function
                      var refresh = function(event) {
                        var fileName = require('path').relative(__dirname, event.path);
                        gutil.log.apply(gutil, [gutil.colors.magenta(fileName), gutil.colors.cyan('built')]);
                        lr.changed({
                          body: { files: [fileName] }
                        });
                      };
                  

                  推荐答案

                  我已经通过在我的 gulpfile.js 中编写一个简单的 javascript 函数来实现这一点

                  I have achieve this by writing a simple javascript function in my gulpfile.js

                  我这样做是因为当我编译我的 sass 文件时,livereload 会运行大约 10 次,这种方法会使其只运行一次.

                  I did this because when I compile my sass files, livereload will run around 10 times, this method will make it only run once.

                  我的 gulpfile.js

                  gulp.task('watch', function() {
                      $.livereload.listen();
                  
                      gulp.watch([
                          path.join(config.path.app, 'media/js/**/*.js'),
                          path.join(config.path.app, 'media/css/**/*.css'),
                          path.join(config.path.app, 'templates/**/*.html')
                      ]).on('change', stackReload);
                  
                      // a timeout variable
                      var timer = null;
                  
                      // actual reload function
                      function stackReload() {
                          var reload_args = arguments;
                  
                          // Stop timeout function to run livereload if this function is ran within the last 250ms
                          if (timer) clearTimeout(timer);
                  
                          // Check if any gulp task is still running
                          if (!gulp.isRunning) {
                              timer = setTimeout(function() {
                                  $.livereload.changed.apply(null, reload_args);
                              }, 250);
                          }
                      }
                  
                  });
                  

                  这篇关于我可以将 gulp livereload 设置为在所有文件编译后运行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:React.js app.js 文件大小 下一篇:将 Gulp glob 链接到浏览器化转换

                  相关文章

                  最新文章

                  1. <small id='cQekQ'></small><noframes id='cQekQ'>

                    <legend id='cQekQ'><style id='cQekQ'><dir id='cQekQ'><q id='cQekQ'></q></dir></style></legend>
                    <i id='cQekQ'><tr id='cQekQ'><dt id='cQekQ'><q id='cQekQ'><span id='cQekQ'><b id='cQekQ'><form id='cQekQ'><ins id='cQekQ'></ins><ul id='cQekQ'></ul><sub id='cQekQ'></sub></form><legend id='cQekQ'></legend><bdo id='cQekQ'><pre id='cQekQ'><center id='cQekQ'></center></pre></bdo></b><th id='cQekQ'></th></span></q></dt></tr></i><div id='cQekQ'><tfoot id='cQekQ'></tfoot><dl id='cQekQ'><fieldset id='cQekQ'></fieldset></dl></div>
                    • <bdo id='cQekQ'></bdo><ul id='cQekQ'></ul>

                  2. <tfoot id='cQekQ'></tfoot>