for transforming sass to css
{
"name": "gulp",
"version": "1.0.0",
"description": "my project",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="css/styles.min.css">
</head>
<body>
<main class="main">
<article class="main__article">
Hi, <span class="main__article--marked-text">mr. Brown</span>.
</article>
</main>
</body>
</html>
.main {
&__article {
&--marked-text {
color: magenta;
}
}
}
so maybe it would be necessary to install Ruby
'use strict';
var gulp = require("gulp"),
del = require('del'),
sass = require('gulp-sass'),
scssLint = require('gulp-scss-lint'),
scssLintStylish = require('gulp-scss-lint-stylish'),
cleanCSS = require('gulp-clean-css'),
rename = require("gulp-rename"),
sourcemaps = require('gulp-sourcemaps');
gulp.task("styles", function(){
return gulp.src("scss/entry.scss")
.pipe(scssLint({ customReport: scssLintStylish }))
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(rename({
basename: "styles",
suffix: ".min"
}))
.pipe(cleanCSS())
.pipe(sourcemaps.write())
.pipe(gulp.dest("css"))
});
gulp.task('clean', function(cb) {
return del(['css'], cb);
});
gulp.task('default', ['clean'], function() {
gulp.start('styles');
});
{
"name": "gulp",
"version": "1.0.0",
"description": "my project",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"del": "^2.2.2",
"gulp": "^3.9.1",
"gulp-clean-css": "^2.0.13",
"gulp-rename": "^1.2.2",
"gulp-sass": "^2.3.2",
"gulp-scss-lint": "^0.4.0",
"gulp-scss-lint-stylish": "^1.0.1",
"gulp-sourcemaps": "^1.6.0",
"node-sass": "^3.10.1"
}
}
Install the watcher at first: npm i gulp-watch --save-dev
Then define it in the gulpfile.js: watch = require('gulp-watch');
/* adding 'watch' task */
gulp.task('watch', function() {
gulp.watch('scss/**/*.scss',
['styles']);
});
/* fixing 'default' task */
gulp.task('default', ['clean'],
function() {
gulp.start('styles', 'watch');
}
);