Gulp 大口-SCSS皮棉-唐';如果linting失败,请不要编译SCS

Gulp 大口-SCSS皮棉-唐';如果linting失败,请不要编译SCS,gulp,lint,gulp-watch,gulp-sass,Gulp,Lint,Gulp Watch,Gulp Sass,只是想知道是否有人能帮我做一下吞咽设置。目前,我正在使用gulp sass和gulp scss lint执行手表任务。我希望发生的是,当保存scss文件以便linting任务完全运行时,如果出现任何错误或警告,则scss文件将无法编译,而watch将继续运行 目前,我似乎可以处理错误,但不能处理仍然编译样式表的警告 /// <binding ProjectOpened='serve' /> // Macmillan Volunteering Village Gulp file. /

只是想知道是否有人能帮我做一下吞咽设置。目前,我正在使用gulp sass和gulp scss lint执行手表任务。我希望发生的是,当保存scss文件以便linting任务完全运行时,如果出现任何错误或警告,则scss文件将无法编译,而watch将继续运行

目前,我似乎可以处理错误,但不能处理仍然编译样式表的警告

/// <binding ProjectOpened='serve' />
//  Macmillan Volunteering Village Gulp file.
//  This is used to automate the minification
//  of stylesheets and javascript files. Run using either
//  'gulp', 'gulp watch' or 'gulp serve' from a command line terminal.
//
//  Contents
//  --------
//    1. Includes and Requirements
//    2. SASS Automation
//    3. Live Serve
//    4. Watch Tasks
//    5. Build Task

'use strict';

//
//  1. Includes and Requirements
//  ----------------------------
//  Set the plugin requirements
//  for Gulp to function correctly.
var gulp = require('gulp'),
  notify = require("gulp-notify"),
  sass = require('gulp-sass'),
  scssLint = require('gulp-scss-lint'),
  gls = require('gulp-live-server'),

//  Set the default folder structure
//  variables
  styleSheets = 'Stylesheets/',
  styleSheetsDist = 'Content/css/',
  html = 'FrontEnd/';

//
//  2. SASS Automation
//  ------------------
//  Includes the minification of SASS
//  stylesheets. Output will be compressed.
gulp.task('sass', ['scss-lint'], function () {
  gulp.src(styleSheets + 'styles.scss')
  .pipe(sass({
    outputStyle: 'compressed'
  }))
  .on("error", notify.onError(function (error) {
    return error.message;
  }))
  .pipe(gulp.dest(styleSheetsDist))
  .pipe(notify({ message: "Stylesheets Compiled", title: "Stylesheets" }))
});

//  SCSS Linting. Ignores the reset file
gulp.task('scss-lint', function () {
  gulp.src([styleSheets + '**/*.scss', '!' + styleSheets + '**/_reset.scss'])
  .pipe(scssLint({
    'endless': true
  }))
  .on("error", notify.onError(function (error) {
    return error.message;
  }))
});

//
//  3. Live Serve
//  -------------
gulp.task('server', function () {
  var server = gls.static('/');
  server.start();

  // Browser Refresh
  gulp.watch([styleSheets + '**/*.scss', html + '**/*.html'], function () {
    server.notify.apply(server, arguments);
  });
});

//  Task to start the server, followed by watch
gulp.task('serve', ['default', 'server', 'watch']);


//
//  4. Watch Tasks
//  --------------
gulp.task('watch', function () {

  // Stylesheets Watch
  gulp.watch(styleSheets + '**/*.scss', ['scss-lint', 'sass']);
});

//
//  5. Build Task
//  --------------
gulp.task('default', ['sass']);
//
//麦克米伦志愿村吞咽文件。
//这用于自动化缩小
//样式表和javascript文件。使用其中一个运行
//从命令行终端“咕噜咕噜”、“咕噜咕噜手表”或“咕噜咕噜服务”。
//
//内容
//  --------
//    1. 包括和要求
//    2. SASS自动化
//    3. 现场发球
//    4. 观察任务
//    5. 构建任务
"严格使用",;
//
//  1. 包括和要求
//  ----------------------------
//设置插件要求
//为了使吞咽功能正常。
var gulp=需要('gulp'),
通知=要求(“吞咽通知”),
sass=require('gulp-sass'),
scssLint=需要('gulp-scss-lint'),
gls=require('gulp-live-server'),
//设置默认文件夹结构
//变数
样式表='styleSheets/',
styleSheetsDist='Content/css/',
html='FrontEnd/';
//
//  2. SASS自动化
//  ------------------
//包括SASS的小型化
//样式表。输出将被压缩。
吞咽任务('sass',['scss-lint',函数(){
gulp.src(样式表+styles.scss)
.管道(sass)({
outputStyle:“压缩”
}))
.on(“错误”,notify.onError(函数(错误){
返回错误消息;
}))
.管道(吸气目的地(样式表列表))
.pipe(通知({消息:“已编译的样式表”,标题:“样式表”}))
});
//SCSS皮棉。忽略重置文件
吞咽任务('scss-lint',函数(){
gulp.src([styleSheets+'***.scss','!'+styleSheets+'***/_reset.scss']))
.管道(scssLint({
"无止境":对
}))
.on(“错误”,notify.onError(函数(错误){
返回错误消息;
}))
});
//
//  3. 现场发球
//  -------------
gulp.task('server',function(){
var server=gls.static('/');
server.start();
//浏览器刷新
gulp.watch([styleSheets+'***.scss',html+'***.html'],函数(){
server.notify.apply(服务器,参数);
});
});
//任务启动服务器,然后是监视
任务('SERVICE'、['default'、'server'、'watch']);
//
//  4. 观察任务
//  --------------
吞咽任务('watch',函数(){
//样式表手表
大口观看(样式表+'***.scss',['scss-lint','sass']);
});
//
//  5. 构建任务
//  --------------
吞咽任务('default',['sass']);

2015年,@juanfran似乎在GitHub上回答了这个问题。我就把它转贴在这里

1) 如果您可以添加任何您喜欢的条件,请使用吞咽

var sass = require('gulp-sass');
var gulpif = require('gulp-if');
var scssLint = require('gulp-scss-lint')

gulp.task('lint', function() {
    var condition = function(file) {
        return !(file.scssLint.errors || file.scssLint.warnings);
    };

    return gulp.src('**/*.scss')
        .pipe(scssLint())
        .pipe(gulpif(condition, sass()));
});
2) 另一个更具体的选项是使用失败报告程序,如果出现任何错误或警告,该报告程序将失败

gulp.task('scss-lint', function() {
    return gulp.src('**/*.scss')
        .pipe(scssLint())
        .pipe(scssLint.failReporter());
});

gulp.task('sass', ['scss-lint'], function() {
    return gulp.src('**/*.scss')
        .pipe(scss());
});