Len ma zaujímalo, či mi niekto môže pomôcť s mojímGulp setup. Momentálne používam hltanovú špargľu a hltanovo-scss-vlákna so strážnou úlohou. Chcem sa stať, že keď sa súbor scss uloží, aby sa operácia lintingu spustila úplne a či sa vyskytnú nejaké chyby alebo varovania, súbory scss sa nezkompilujú a hodinky sa budú naďalej zobrazovať.
Zdá sa, že v tejto chvíli pracujem s chybami, ale nie s varovaniami, ktoré stále zostavujú zoznamy štýlov.
/// <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"]);
odpovede:
0 pre odpoveď č. 1Zdá sa, že @juanfran odpovedal na túto otázku v službe GitHub v roku 2015. Budem ju tu uvádzať znova.
1) Použitie dúšok, ak môžete pridať ľubovoľnú podmienku.
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) Ďalšou konkrétnejšou možnosťou je použitie Zlyhanie reportéra ktoré zlyhajú v prípade akýchkoľvek chýb alebo upozornení
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());
});