【问题标题】:How can I make 'gulp watch' command work?如何使“gulp watch”命令起作用?
【发布时间】:2019-09-01 11:54:01
【问题描述】:

浏览器控制台不监视错误,但是当我尝试在 git 控制台中运行命令时出现错误。

let gulp = require('gulp');
let sass = require('gulp-sass');
let watch = require('gulp-watch');
let browserSync = require('browser-sync');

gulp.task('sass', function() {
    return gulp.src('src/scss/index.scss')
        .pipe(sass().on('error', sass.logError))
        .pipe(gulp.dest('src/css/index.css'))
});

gulp.task('sass:watch', function() {
    gulp.watch('src/scss/index.scss', ['sass']);
});

gulp.task('browser-sync', function() {
    browserSync({
        server: {
            baseDir: 'src'
        },
        notify: false
    });
});

链接到我的存储库https://github.com/dzhulay/Step-Ham

【问题讨论】:

  • 你能把错误贴出来吗?
  • 错误:正在观看 src/scss/index.scss:监视任务必须是 Gulp.watch (C:\Step-Ham \node_modules\gulp\index.js:31:11) 在 C:\Step-Ham\gulpfile.js:14:10 在 taskWrapper (C:\Step-Ham\node_modules\undertaker\lib\set-task.js: 13:15) at bound (domain.js:402:14) at runBound (domain.js:415:12) at asyncRunner (C:\Step-Ham\node_modules\async-done\index.js:55:18)在 process._tickCallback (internal/process/next_tick.js:61:11)

标签: javascript gulp-watch


【解决方案1】:

gulp.watch 函数需要一个文件列表和一个函数作为第二个参数。

您必须使用gulp.parallelgulp.series 生成函数,例如您的情况:

gulp.task('watch', function() {
    gulp.watch('src/scss/index.scss', gulp.series('sass'));
});

另外,为了避免您评论中指定的“文件存在”错误,请在您的 sass 任务中实现“gulp-chmod”,例如:

var chmod = require('gulp-chmod');

gulp.task('sass', function() {
return gulp.src('src/scss/index.scss')
    .pipe(chmod(0o755))
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest('src/css/index.css'))
});    

【讨论】:

  • 现在我有一个错误 EEXIST: file already exists, mkdir 'C:\Step-Ham\src\css\index.css'
  • 在这里使用 gulp-chmod:stackoverflow.com/questions/43798562/…
  • 我尝试使用该变体,但现在出现此错误:正在观看 src/scss/index.scss: watch task has to be a function(可选地使用 gulp.parallel 或 gulp.series 生成)在 Gulp.watch (C:\Step-Ham\node_modules\gulp\index.js:31:11) 在 C:\Step-Ham\gulpfile.js:13:10 在 taskWrapper (C:\Step-Ham\node_modules \undertaker\lib\set-task.js:13:15) at bound (domain.js:402:14) at runBound (domain.js:415:12) at asyncRunner (C:\Step-Ham\node_modules\async -done\index.js:55:18) 在 process._tickCallback (internal/process/next_tick.js:61:11)
  • 没有“require('gulp-watch');”?
  • 我已经更新了我的代码,我尝试使用 'require gulp' 运行它,但没有任何效果
猜你喜欢
  • 2014-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多