简体   繁体   English

为什么观看任务终止于gulp已经使用gulp-plumber插件?

[英]Why watch task terminate in gulp already use gulp-plumber plugin?

I try to use this plugin in gulp (gulp-plumber).I studied about this plugin that it gives you error but it watching state not stop.In other words it gives your file error on command line.But it not stop watching . 我尝试在gulp(gulp-plumber)中使用此插件。我研究了该插件,它给您带来错误,但是它的观看状态没有停止。换句话说,它在命令行上给了您文件错误的信息,但是它并没有停止观看。 https://www.npmjs.com/package/gulp-plumber https://www.npmjs.com/package/gulp-plumber

But when I changed in sass file try to create error on saas file ,then it stop watch then Again i need to give command why ? 但是,当我更改sass文件时,尝试在saas文件上创建错误,然后停止计时,然后再次需要命令为什么?

here id my gulp file. 这是我的gulp文件。

var gulp = require('gulp');
//require sass package
var sass = require('gulp-sass');
var rename = require('gulp-rename');
var minifyCss = require('gulp-minify-css');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var plumber = require('gulp-plumber');




// Compile Our Sass
gulp.task('sass', function () {
    return gulp.src('scss/*.scss')
        .pipe(sass())
        .pipe(plumber())
        .pipe(gulp.dest('css'));
});
// css miifilcation
gulp.task('minify-css',['sass'], function () {
    return gulp.src('css/*.css')
        .pipe(minifyCss())
        .pipe(plumber())
        .pipe(rename({suffix: '.min'}))
        .pipe(gulp.dest('dist'));
});

// js minifiction
gulp.task('compress', function() {
    return gulp.src('app/**/*.js')
        .pipe(uglify())
        .pipe(gulp.dest('jdist'));
});

//concatination of js files

gulp.task('scripts', function() {
    return gulp.src('jdist/**/*.js')
        .pipe(concat('all.js'))
        .pipe(rename({suffix: '.min'}))
        .pipe(gulp.dest('dist/'));
});


// Watch Files For Changes
gulp.task('watch', function () {
    gulp.watch('scss/*.scss', ['sass','minify-css']);
});

gulp.task('default', ['sass', 'watch', 'minify-css','scripts']);

these are following steps I did. 这些是我执行的步骤。

  • Write gulp in command line 在命令行中编写gulp
  • change in sass file .remove one '{ in saas file then it give the error and terminate why ? 更改sass文件。在saas文件中删除一个'{ ,然后给出错误并终止为什么?

here is my log 这是我的日志

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

D:\Webapplication\DemoApp>gulp
[09:11:47] Using gulpfile D:\Webapplication\DemoApp\gulpfile.js
[09:11:47] Starting 'sass'...
[09:11:47] Starting 'watch'...
[09:11:47] Finished 'watch' after 9.13 ms
[09:11:47] Starting 'scripts'...
[09:11:47] Finished 'sass' after 53 ms
[09:11:47] Starting 'minify-css'...
[09:11:47] Finished 'minify-css' after 27 ms
[09:11:47] Finished 'scripts' after 61 ms
[09:11:47] Starting 'default'...
[09:11:47] Finished 'default' after 7.5 µs
[09:13:23] Starting 'sass'...

events.js:141
      throw er; // Unhandled 'error' event
      ^
 Error: scss\home.scss
Error: Invalid CSS after "}": expected "}", was ""
        on line 28 of stdin
>> }
   ^

    at options.error (D:\Webapplication\DemoApp\node_modules\gulp-sass\node_modules\node-sass\lib\index.js:277:32)

D:\Webapplication\DemoApp>

update Question after answer.I apply your answer .it is not terminating but after it is also not watching way? 更新答案后的问题。我应用您的答案。它不是终止,但是之后也没有观看?

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

D:\Webapplication\DemoApp>gulp
[10:43:28] Using gulpfile D:\Webapplication\DemoApp\gulpfile.js
[10:43:28] Starting 'watch'...
[10:43:28] Finished 'watch' after 20 ms
[10:43:28] Starting 'default'...
[10:43:28] Finished 'default' after 7.11 µs
[10:43:42] Starting 'sass'...
[10:43:42] Finished 'sass' after 32 ms
[10:43:42] Starting 'minify-css'...
[10:43:42] Finished 'minify-css' after 30 ms
[10:43:49] Starting 'sass'...
[10:43:49] Plumber found unhandled error:
 Error in plugin 'gulp-sass'
Message:
    scss\home.scss
Error: Invalid CSS after "}": expected "}", was ""
        on line 28 of stdin
>> }
   ^

Details:
    formatted: Error: Invalid CSS after "}": expected "}", was ""
        on line 28 of stdin
>> }
   ^

    column: 1
    line: 28
    file: stdin
    status: 1
    messageFormatted: scss\home.scss
Error: Invalid CSS after "}": expected "}", was ""
        on line 28 of stdin
>> }
   ^

Try swaping sass and plubmber in your sass task as it is shown in the example on gulp plumber page. 尝试在sass任务中交换sass和plubmber,如gulp水管工页面上的示例所示。 Your task should look like this 您的任务应如下所示

// Compile Our Sass
gulp.task('sass', function () {
    return gulp.src('scss/*.scss')
        .pipe(plumber({
              handleError: function (err) {
                               console.log(err);
                               this.emit('end');
                           }
         }))
        .pipe(sass())
        .pipe(gulp.dest('css'));
});

Update 更新资料

I took out the js tasks for simplicity of my answer. 为了简化答案,我取出了js任务。 Now you are compiling your sass, minifying it and adding min to name in a single task. 现在,您正在编译sass,将其最小化并在单个任务中将min添加到名称中。

// SASS 
gulp.task('sass', function () {
    return gulp.src('scss/*.scss')
        .pipe(plumber())
        .pipe(sass({outputStyle: 'compressed'}))
        .pipe(rename({suffix: '.min'}))
        .pipe(gulp.dest('dist'));
});


// Watch Files For Changes
gulp.task('watch', function () {
    gulp.watch('scss/*.scss', ['sass']);
});

gulp.task('default', ['sass', 'watch']);

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

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