Gulp run alternative

后端 未结 3 1933
旧时难觅i
旧时难觅i 2021-01-13 14:31

Everytime I run gulp, I see this message gulp.run() has been deprecated. Use task dependencies or gulp.watch task triggering instead.

Example code:

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-13 15:18

    You can always just use plain old javascript functions. From what i've read this is considered to be a more "gulp-ish" way of doing things.

    I ran into a similar situation once and basically solved it with something like this:

    var watch = require('gulp-watch');
    watch(['public/**/*.js','!public/**/*.min.js'], function(){
        compress();
        bsReload();
    });
    

    And then these functions are basically wrappers around the guts of what would have been your original gulp tasks:

    var compress = function () {
      return gulp.src("stuff/**")
              .pipe(gulp-compress())
              .pipe(gulp.dest("./the_end/");
    };
    

    Its easy to become caught up in the idea that one has to use gulp tasks for everything otherwise you are "doing it wrong" but if you need to use something like this go for it.

    If you also want a gulp task with the same functionality then whip up something like this:

    gulp.task("compress", function () {
      return compress();
    });
    

    and you can still take advantage of gulp task dependecies when using the same code if you need it somewhere else.

提交回复
热议问题