简体   繁体   English

Gulp 手表未完成

[英]Gulp watch doesn't finished

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] Using gulpfile C:\xampp\htdocs\drupal-8.7.9\drupal-8.7.9\themes\custom\sebastian\gulpfile.js [18:40:58] 使用 gulpfile C:\xampp\htdocs\drupal-8.7.9\drupal-8.7.9\themes\custom\sebastian\gulpfile.js

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

Why does it not finish the watch?为什么手表不走完?

Gulp watch doesn't create a css folder in the sebastian folder. Gulp 手表不会在 sebastian 文件夹中创建 css 文件夹。

The watch task doesn't finish because you didn't terminate that task - like you did with the return statements in the other tasks. watch任务没有完成,因为您没有终止该任务 - 就像您在其他任务中使用return语句所做的那样。 But that is a good thing.但这是一件好事。

You do not want the watch task to terminate - you want it to keep watching files as you edit them and the watch task will then trigger the other tasks.您不希望watch任务终止 - 您希望它在编辑文件时继续监视文件,然后watch任务将触发其他任务。

The watch task on its own - like on first run - will not trigger the sass task until you edit a .scss file that it is watching. watch任务本身 - 就像第一次运行一样 - 不会触发sass任务,直到您编辑它正在监视的.scss文件。 As soon as you do that, the sass task should be triggered and your output .css file be created.执行此操作后,应立即触发sass任务并创建 output .ZC7A62 .css文件。

There are options to have the watch task be triggered on first run if that is really what you wish.如果这确实是您想要的,可以选择在第一次运行时触发watch任务。 But it doesn't sound like that is your issue.但这听起来不像是你的问题。

  • add function callback in functions task在函数任务中添加 function 回调
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()
});

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

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