简体   繁体   English

为什么我的gulp任务不关注变化?

[英]Why are my gulp tasks not watching for changes?

I'm having trouble configuring my gulp file to watch. 我在配置要观看的gulp文件时遇到问题。 When I run the default task it runs all of the jobs that it's supposed to but if I add a file or make changes to any of the SCSS files it doesn't run the sass job (I'm also assuming that it wouldn't run imagemin or js-watch). 当我运行默认任务时,它将运行所有应有的任务,但是如果我添加文件或对任何SCSS文件进行更改,它将不会运行sass任务(我还假设它不会运行imagemin或js-watch)。

Below is my gulp file 以下是我的gulp文件

var pkg = require('./package.json');
var gulp = require('gulp');

const BrowserSync = require('./gulp-tasks/browser-sync');
const Sass = require('./gulp-tasks/sass');
const Scripts = require('./gulp-tasks/scripts');
const Svg = require('./gulp-tasks/svg-sprite');
const Img = require('./gulp-tasks/img-min');

gulp.task('browser-sync-init', BrowserSync.initialize);
gulp.task('js-watch', ['js'], BrowserSync.reload);
gulp.task('reload-watch', ['copy'], BrowserSync.reload);

gulp.task('sass', Sass.build);

gulp.task('lint', Scripts.lint);
gulp.task('js', ['lint'], Scripts.build);

gulp.task('copy', function(){
    gulp.src(`${pkg.config.themeRoot}/**/*.html`)
        .pipe(gulp.dest(pkg.config.dist));
});

gulp.task('imagemin', Img.imgmin);

gulp.task('svg', Svg.build);

gulp.task('default', ['sass', 'js', 'imagemin', 'browser-sync-init'], function(){
    gulp.watch(`${pkg.config.scss}/**/*.scss`, ['sass']);
    gulp.watch(`${pkg.config.scripts}/**/*.js`, ['js-watch']);
    gulp.watch(`${pkg.config.images}/source/**`, ['imagemin']);
});

And this is the definition for pkg.config.scss 这是pkg.config.scss的定义

"scss": "wp-content/themes/grpw67000/assets/scss",

What could I be doing wrong? 我可能做错了什么?

    var pkg = require('./package.json');
    var gulp = require('gulp');

    const BrowserSync = require('./gulp-tasks/browser-sync');
    const Sass = require('./gulp-tasks/sass');
    const Scripts = require('./gulp-tasks/scripts');
    const Svg = require('./gulp-tasks/svg-sprite');
    const Img = require('./gulp-tasks/img-min');

    gulp.task('browser-sync-init', BrowserSync.initialize);
    gulp.task('js-watch', ['js'], BrowserSync.reload);
    gulp.task('reload-watch', ['copy'], BrowserSync.reload);

    gulp.task('sass', Sass.build);

    gulp.task('lint', Scripts.lint);
    gulp.task('js', ['lint'], Scripts.build);

    gulp.task('copy', function(){
        gulp.src(`${pkg.config.themeRoot}/**/*.html`)
            .pipe(gulp.dest(pkg.config.dist));
    });

    gulp.task('imagemin', Img.imgmin);

    gulp.task('svg', Svg.build);

    // Watch task for gulp
    gulp.task('watch', function () {
       gulp.watch(`${pkg.config.scss}/**/*.scss`, ['sass']);
       gulp.watch(`${pkg.config.scripts}/**/*.js`, ['js-watch']);
       gulp.watch(`${pkg.config.images}/source/**`, ['imagemin']);
    });

    gulp.task('default', ['sass', 'js', 'imagemin', 'browser-sync-init', 'watch']);

Try adding a separate gulp task for watch functionality. 尝试添加一个单独的gulp任务watch功能。 If this is not working check if the 如果这不起作用,请检查

${pkg.config.scss}

Correctly set the path prefix. 正确设置路径前缀。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM