Gulp即使存在lint错误也符合Sass

时间:2018-02-13 06:55:05

标签: css gulp gulp-watch gulp-sass

我在 scss 文件编译为 css 之前使用过gulp-sass-lint。我在这里面临的问题是,即使scss中存在linting错误,scss也会被编译为css。

如果有丢失错误,如何停止scss编译为css。

This is My Folder Structure

这是我的gulpfile。

var gulp        = require('gulp');
var browserSync = require('browser-sync').create();
var sass        = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var cssmin = require('gulp-cssmin');
var rename = require('gulp-rename');
var sassLint = require('gulp-sass-lint');

// Static Server + watching scss/html files
gulp.task('serve', ['sass-lint'], function() {
    browserSync.init({
        server: "./app"
    });
    gulp.watch("app/scss/*.scss", ['sass-lint']);
    gulp.watch("app/*.html").on('change', browserSync.reload);
    gulp.watch("app/js/*.js").on('change', browserSync.reload);
});

// sass-lint check
gulp.task('sass-lint', function () {
  return gulp.src('app/scss/**/*.s+(a|c)ss')
    .pipe(sassLint())
    .pipe(sassLint.format())
    .pipe(sassLint.failOnError())
    .pipe(sass().on('error',sass.logError))
    .pipe(gulp.dest("app/css"))
    .pipe(sourcemaps.init())
    .pipe(cssmin())
    .pipe(sourcemaps.write())
    .pipe(rename({
        suffix:'.min'
    }))
    .pipe(gulp.dest('app/css'))
    .pipe(browserSync.stream());
});

gulp.task('default', ['serve']);

这是我的package.json文件

{
  "name": "gulpscss_starterkit",
  "version": "1.0.0",
  "description": "",
  "main": "gulpfile.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "gulp"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "browser-sync": "^2.22.0",
    "gulp": "^3.9.1",
    "gulp-cssmin": "^0.2.0",
    "gulp-rename": "^1.2.2",
    "gulp-sass": "^3.1.0",
    "gulp-sass-lint": "^1.3.4",
    "gulp-sourcemaps": "^2.6.3"
  }
}

1 个答案:

答案 0 :(得分:0)

我会把sassLint放到自己的任务中。

library(ggplot2) # only to get the diamonds data.frame

data.frame(Factors=colnames(diamonds), 
           t(sapply(diamonds, # apply following function to each column
                    function(x) {
                        t_x <- sort(table(x), decreasing=TRUE) # get the frequencies and sort them in decreasing order
                        list(Categories=names(t_x)[1], # name of the value with highest frequency
                             Frequency=t_x[1]) # highest frequency
                    })))
#        Factors Categories Frequency
#carat     carat        0.3      2604
#cut         cut      Ideal     21551
#color     color          G     11292
#clarity clarity        SI1     13065
#depth     depth         62      2239
#table     table         56      9881
#price     price        605       132
#x             x       4.37       448
#y             y       4.34       437
#z             z        2.7       767