Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
The gulp-sass package is a Gulp plugin that allows you to compile Sass (Syntactically Awesome Stylesheets) files into CSS. It integrates seamlessly with Gulp, a toolkit for automating painful or time-consuming tasks in your development workflow.
Compile Sass to CSS
This feature allows you to compile Sass files into CSS. The code sample demonstrates a Gulp task that takes all .scss files from the src/scss directory, compiles them into CSS, and outputs them to the dist/css directory.
const gulp = require('gulp');
const sass = require('gulp-sass')(require('sass'));
gulp.task('sass', function() {
return gulp.src('./src/scss/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./dist/css'));
});
Watch for changes
This feature allows you to watch for changes in your Sass files and automatically compile them to CSS whenever a change is detected. The code sample demonstrates a Gulp task that watches the src/scss directory for changes and runs the 'sass' task whenever a change is detected.
const gulp = require('gulp');
const sass = require('gulp-sass')(require('sass'));
gulp.task('sass', function() {
return gulp.src('./src/scss/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./dist/css'));
});
gulp.task('watch', function() {
gulp.watch('./src/scss/**/*.scss', gulp.series('sass'));
});
Source Maps
This feature allows you to generate source maps for your compiled CSS files, which can be useful for debugging. The code sample demonstrates a Gulp task that initializes source maps, compiles Sass to CSS, writes the source maps to a maps directory, and outputs the CSS to the dist/css directory.
const gulp = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const sourcemaps = require('gulp-sourcemaps');
gulp.task('sass', function() {
return gulp.src('./src/scss/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('./dist/css'));
});
node-sass is a library that provides binding for Node.js to LibSass, the C version of the popular stylesheet preprocessor, Sass. It can be used independently or integrated into build tools like Gulp or Grunt. Compared to gulp-sass, node-sass is more low-level and requires additional setup to integrate with Gulp.
sass is the official Dart implementation of Sass, which is the primary implementation used by the Sass team. It can be used with Node.js and is often preferred for its speed and compatibility with the latest Sass features. Like node-sass, it can be integrated into Gulp but requires additional configuration.
gulp-less is a Gulp plugin for compiling Less files to CSS. While it serves a similar purpose to gulp-sass, it is specifically designed for Less, another CSS preprocessor. It offers similar functionality but is not compatible with Sass files.
Sass plugin for Gulp.
npm install gulp-sass --save-dev
Something like this will compile your Sass files:
var gulp = require('gulp');
var sass = require('gulp-sass');
gulp.task('sass', function () {
gulp.src('./scss/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
You can also compile synchronously, doing something like this:
var gulp = require('gulp');
var sass = require('gulp-sass');
gulp.task('sass', function () {
gulp.src('./scss/*.scss')
.pipe(sass.sync().on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
Pass in options just like you would for node-sass
; they will be passed along just as if you were using node-sass
.
gulp-sass
can be used in tandem with gulp-sourcemaps to generate source maps for the Sass to CSS compilation. You will need to initialize gulp-sourcemaps prior to running gulp-sass
and write the source maps after.
var sourcemaps = require('gulp-sourcemaps');
gulp.src('./scss/*.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(sourcemaps.write())
.pipe(gulp.dest('./css'));
By default, gulp-sourcemaps writes the source maps inline in the compiled CSS files. To write them to a separate file, specify a path relative to the gulp.dest()
destination in the sourcemaps.write()
function.
var sourcemaps = require('gulp-sourcemaps');
gulp.src('./scss/*.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('./css'));
gulp-sass
is a very light-weight wrapper around node-sass
, which in turn is a Node binding for libsass
, which in turn is a port of Sass
. Because of this, the issue you're having likely isn't a gulp-sass
issue, but an issue with one of those three projects.
If you have a feature request/question how Sass works/concerns on how your Sass gets compiled/errors in your compiling, it's likely a libsass
or Sass
issue and you should file your issue with one of those projects.
If you're having problems with the options you're passing in, it's likely a node-sass
or libsass
issued and you should file your issue with one of those projects.
We may, in the course of resolving issues, direct you to one of these other projects. If we do so, please follow up by searching that project's issue queue (both open and closed) for your problem and, if it doesn't exist, filing an issue with them.
v2.0.0-alpha.1
March 26, 2015
renderSync
option that can be used through sass.sync()
node-sass
3.0.0-alpha.1gulp-sourcemaps
including tests.editorconfig
for development consistencylogError
function to make streaming errors possible instead of breaking the streamFAQs
Gulp plugin for sass
The npm package gulp-sass receives a total of 273,363 weekly downloads. As such, gulp-sass popularity was classified as popular.
We found that gulp-sass demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.