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

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

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

        <bdo id='lbH95'></bdo><ul id='lbH95'></ul>
    2. 将 gulp@3.9.1 中的 gulp watch 转换为 gulp@4

      时间:2023-05-29
      <tfoot id='wtMpO'></tfoot>

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

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

                本文介绍了将 gulp@3.9.1 中的 gulp watch 转换为 gulp@4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我们正在从 gulp@3.9.1 切换到 gulp@4 并且在切换时遇到问题.当我们运行 gulp watch 时,我们会收到以下错误并试图找出解决方法.

                We are switching from gulp@3.9.1 to gulp@4 and are having trouble switching over. When we run gulp watch, we are getting the following errors and trying to figure out how to resolve it.

                gulp watch 任务转换为使用 gulp@4 的正确方法是什么?

                What is the proper way to convert the gulp watch task to work with gulp@4?

                错误信息

                AssertionError [ERR_ASSERTION]:任务从未定义:minify-css

                AssertionError [ERR_ASSERTION]: Task never defined: minify-css

                命令:gulp watch

                • 这应该按顺序运行 minify-js 然后 minify-css
                • minify-js 应该在 clean-scripts 成功完成后运行
                • minify-css 应该在 clean-css 成功完成后运行
                • This should run minify-js then minify-css in order
                • minify-js should run after clean-scripts has completed successfully
                • minify-css should run after clean-css has completed successfully

                当前任务.

                var gulp = require('gulp'),
                    cssmin = require('gulp-clean-css'),
                    clean = require('gulp-clean'),
                    uglify = require('gulp-uglify');
                    
                var src = {
                  js: 'js/some-dir/**/*.js',
                  css: 'css/some-dir/**/*.css'
                };
                
                var dest = {
                  js: 'js/dest/some-dir/**/*.js',
                  css: 'css/dest/some-dir/**/*.css'
                };
                
                gulp.task('clean-css', function() {
                  return gulp.src(dest.css)
                             .pipe(clean({read:false, force: true});
                });
                
                gulp.task('minify-css', ['clean-css'], function() {
                  gulp.src(src.css)
                    .pipe(cssmin())
                    .pipe(gulp.dest(dest.css));
                });
                
                gulp.task('clean-scripts', function() {
                  return gulp.src(dest.js)
                             .pipe(clean({read:false, force: true});
                });
                
                gulp.task('minify-js', ['clean-scripts'], function() {
                   gulp.src(src.js)
                       .pipe(uglify())
                       .pipe(gulp.dest(dest.js));
                });
                
                gulp.task('watch', ['minify-js', 'minify-css'], function() {
                  gulp.watch(src.js, ['minify-js']);
                  gulp.watch(src.css, ['minify-css']);
                });

                我们尝试这样做,但它导致了错误消息

                gulp.task('watch', gulp.series('minify-js', 'minify-css', function() {
                  gulp.watch(src.js, ['minify-js']);
                  gulp.watch(src.css, ['minify-css']);
                }));

                推荐答案

                我建议你转换你的 minify-js, minify-css, clean-scriptsclean-css 任务到函数:

                I would recommend converting your minify-js, minify-css, clean-scripts and clean-css tasks to functions:

                var dest = {
                  js: 'js/dest/some-dir/**/*.js',
                  css: 'css/dest/some-dir/**/*.css'
                };
                
                function cleanCss() {
                  return gulp.src(dest.css)
                             .pipe(clean({read:false, force: true});
                });
                
                function minifyCss() {
                  return gulp.src(src.css)
                             .pipe(cssmin())
                             .pipe(gulp.dest(dest.css));
                });
                
                function cleanScripts() {
                  return gulp.src(dest.js)
                             .pipe(clean({read:false, force: true});
                });
                
                function minifyJs() {
                   return gulp.src(src.js)
                       .pipe(uglify())
                       .pipe(gulp.dest(dest.js));
                });
                
                var minifyJsAndClean = gulp.series(minifyJs, cleanScripts);
                var minifyCssAndClean = gulp.series(minifyCss, cleanCss);
                var watchers = function (done) {
                   gulp.watch(src.js, minifyJs);
                   gulp.watch(src.css, minifyCss);
                   done();
                }
                
                gulp.task('watch', gulp.series(minifyJsAndClean, minifyCssAndClean, watchers));
                

                这篇关于将 gulp@3.9.1 中的 gulp watch 转换为 gulp@4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何从 GULP 将变量值注入 JS 文件 下一篇:gulp watch 不看

                相关文章

                最新文章

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

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

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