【问题标题】:How to watch files in gulp? [duplicate]如何在 gulp 中查看文件? [复制]
【发布时间】:2020-08-15 11:18:36
【问题描述】:

我正在学习一门过时的 Web 开发课程,但我遇到了与 gulp 相关的问题。我想弄清楚的是如何使用 gulp watch 来观看文件。每当我在命令中点击“gulp watch”时,我都会收到一条错误消息。谁能知道如何解决这个问题?这是我的 gulpfile.js 代码:

<pre>
var gulp = require('gulp'),
watch = require('gulp-watch');

gulp.task('default', function() {
  console.log("This is a gulp task");
});

gulp.task('html', function() {
  console.log("This is your HTML");
});

gulp.task('styles', function() {
  console.log("This is for your css/sass/postcss`enter code here`");
});

gulp.task('watch', function() {

  watch('./app/index.html', function() {
    gulp.start('html');
  });

  watch('./app/assets/styles/**/*.css', function() {
    gulp.start('styles');
  });

});
</pre>

这是错误信息:

(node:7812) UnhandledPromiseRejectionWarning: TypeError: gulp.start is not a function
(node:7812) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:7812) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

【问题讨论】:

标签: javascript node.js gulp


【解决方案1】:

由于 gulp.start 自 v4 以来已被弃用,而您正在使用此版本的 Gulp,您可能想尝试使用 gulp.series 代替:

gulp.task('watch', gulp.series('styles', 'html',  function(done) {
    gulp.watch('./app/assets/styles/**/*.css', gulp.series('styles'));
    gulp.watch('./app/index.html', gulp.series('html'));
    done();
}));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-18
    • 1970-01-01
    • 2019-03-05
    • 2016-02-26
    • 2016-07-18
    • 2012-09-19
    • 2018-02-08
    • 1970-01-01
    相关资源
    最近更新 更多