如何解决如何查看gulp文件?
我正在学习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.
解决方法
由于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();
}));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。