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

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

      1. <tfoot id='flWeh'></tfoot>

        如何使用 gulp 正确清理项目?

        时间:2023-05-29
        <legend id='Apx7L'><style id='Apx7L'><dir id='Apx7L'><q id='Apx7L'></q></dir></style></legend>
        <i id='Apx7L'><tr id='Apx7L'><dt id='Apx7L'><q id='Apx7L'><span id='Apx7L'><b id='Apx7L'><form id='Apx7L'><ins id='Apx7L'></ins><ul id='Apx7L'></ul><sub id='Apx7L'></sub></form><legend id='Apx7L'></legend><bdo id='Apx7L'><pre id='Apx7L'><center id='Apx7L'></center></pre></bdo></b><th id='Apx7L'></th></span></q></dt></tr></i><div id='Apx7L'><tfoot id='Apx7L'></tfoot><dl id='Apx7L'><fieldset id='Apx7L'></fieldset></dl></div>

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

              <tbody id='Apx7L'></tbody>
            <tfoot id='Apx7L'></tfoot>

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

                  本文介绍了如何使用 gulp 正确清理项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  在 gulp 页面上有以下示例:

                  gulp.task('clean', function(cb) {
                    // You can use multiple globbing patterns as you would with `gulp.src`
                    del(['build'], cb);
                  });
                  
                  gulp.task('scripts', ['clean'], function() {
                    // Minify and copy all JavaScript (except vendor scripts)
                    return gulp.src(paths.scripts)
                      .pipe(coffee())
                      .pipe(uglify())
                      .pipe(concat('all.min.js'))
                      .pipe(gulp.dest('build/js'));
                  });
                  
                  // Copy all static images
                  gulp.task('images', ['clean'], function() {
                   return gulp.src(paths.images)
                      // Pass in options to the task
                      .pipe(imagemin({optimizationLevel: 5}))
                      .pipe(gulp.dest('build/img'));
                  });
                  
                  // the task when a file changes
                  gulp.task('watch', function() {
                    gulp.watch(paths.scripts, ['scripts']);
                    gulp.watch(paths.images, ['images']);
                  });
                  
                  // The default task (called when you run `gulp` from cli)
                  gulp.task('default', ['watch', 'scripts', 'images']);
                  

                  这很好用.但是 watch 任务存在一个大问题.如果我更改图像,监视任务会检测到它并运行 images 任务.这对 clean 任务也有依赖 (gulp.task('images', **['clean']**, function() {)),所以这个也运行.但是我的脚本文件丢失了,因为 scripts 任务没有再次启动,并且 clean 任务删除了所有文件.

                  This works quite well. But there is one big problem with the watch task. If I change an image, the watch task detect it and runs the images task. This also has a dependency (gulp.task('images', **['clean']**, function() {) on the clean task, so this runs also. But than my script files are missing because the scripts task did not start again and the clean task deleted all files.

                  如何在第一次启动时运行 clean 任务并保留依赖项?

                  How can I just run the clean task on the first startup and keep the dependencies?

                  推荐答案

                  可以让watch单独触发任务:

                  gulp.task('clean', function(cb) {
                    // You can use multiple globbing patterns as you would with `gulp.src`
                    del(['build'], cb);
                  });
                  
                  var scripts = function() {
                    // Minify and copy all JavaScript (except vendor scripts)
                    return gulp.src(paths.scripts)
                      .pipe(coffee())
                      .pipe(uglify())
                      .pipe(concat('all.min.js'))
                      .pipe(gulp.dest('build/js'));
                  };
                  gulp.task('scripts', ['clean'], scripts);
                  gulp.task('scripts-watch', scripts);
                  
                  // Copy all static images
                  var images = function() {
                   return gulp.src(paths.images)
                      // Pass in options to the task
                      .pipe(imagemin({optimizationLevel: 5}))
                      .pipe(gulp.dest('build/img'));
                  };
                  gulp.task('images', ['clean'], images);
                  gulp.task('images-watch', images);
                  
                  // the task when a file changes
                  gulp.task('watch', function() {
                    gulp.watch(paths.scripts, ['scripts-watch']);
                    gulp.watch(paths.images, ['images-watch']);
                  });
                  
                  // The default task (called when you run `gulp` from cli)
                  gulp.task('default', ['watch', 'scripts', 'images']);
                  

                  这篇关于如何使用 gulp 正确清理项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:events.js: 141 投掷者;//未处理的“错误"事件 下一篇:Gulp less 未正确处理包含未定义的包含变量

                  相关文章

                  最新文章

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

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

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

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