Gulp手表未完成

var gulp = require('gulp');
var livereload = require('gulp-livereload');
var uglify = require('gulp-uglifyjs');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');

gulp.task('imagemin',function() {
    return gulp.src('./themes/custom/sebastian/images/*')
        .pipe(imagemin({
            progressive: true,svgoPlugins: [{ removeViewBox: false }],use: [pngquant()]
        }))
        .pipe(gulp.dest('./themes/custom/sebastian/images'));
});

gulp.task('sass',function() {
    return gulp.src('./themes/custom/sebastian/sass/**/*.scss')
        .pipe(sourcemaps.init())
        .pipe(sass({ outputStyle: 'compressed' }).on('error',sass.logError))
        .pipe(autoprefixer('last 2 version','safari 5','ie 7','ie 8','ie 9','opera 12.1','ios 6','android 4'))
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest('./themes/custom/sebastian/css'));
});

gulp.task('uglify',function() {
    return gulp.src('./themes/custom/sebastian/lib/*.js')
        .pipe(uglify('main.js'))
        .pipe(gulp.dest('./themes/custom/sebastian/js'));
});

gulp.task('watch',function() {
    livereload.listen();
    gulp.watch('./themes/custom/sebastian/sass/**/*.scss',gulp.series('sass'));
    gulp.watch('./themes/custom/sebastian/lib/*.js',gulp.series('uglify'));
    gulp.watch(
        [
            './themes/custom/sebastian/css/style.css','./themes/custom/sebastian/**/*.twig','./themes/custom/sebastian/js/*.js'
        ],function(files) {
            livereload.changed(files);
        }
    );
});
  

[18:40:58]使用gulpfile C:\ xampp \ htdocs \ drupal-8.7.9 \ drupal-8.7.9 \ themes \ custom \ sebastian \ gulpfile.js

     

[18:40:58]开始“观看” ...

为什么不完成手表?

Gulp watch不会在sebastian文件夹中创建一个css文件夹。

mm903795264 回答:Gulp手表未完成

watch任务没有完成,因为您没有终止该任务-就像您在其他任务中使用return语句那样。 但这是一件好事。

您不希望watch任务终止-您希望它在编辑文件时一直监视文件,然后watch任务将触发其他任务。

像您第一次运行一样,watch任务本身不会触发sass任务,除非您编辑正在监视的.scss文件。完成此操作后,应立即触发sass任务并创建输出.css文件。

如果您确实希望这么做,则可以选择在初次运行时触发watch任务。但这听起来不像是您的问题。

,
  • 在函数任务中添加函数回调
gulp.task('watch',function(callback) {
    livereload.listen();
    gulp.watch('./themes/custom/sebastian/sass/**/*.scss',gulp.series('sass'));
    gulp.watch('./themes/custom/sebastian/lib/*.js',gulp.series('uglify'));
    gulp.watch(
        [
            './themes/custom/sebastian/css/style.css','./themes/custom/sebastian/**/*.twig','./themes/custom/sebastian/js/*.js'
        ],function(files) {
            livereload.changed(files);
        }
    );
callback()
});
本文链接:https://www.f2er.com/3131842.html

大家都在问