![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
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.
#Install
npm install gulp-sass
#Basic Usage
Something like this:
var gulp = require('gulp');
var sass = require('gulp-sass');
gulp.task('sass', function () {
gulp.src('./scss/*.scss')
.pipe(sass())
.pipe(gulp.dest('./css'));
});
Options passed as a hash into sass()
will be passed along to node-sass
errLogToConsole: true
If you pass errLogToConsole: true
into the options hash, sass errors will be logged to the console instead of generating a gutil.PluginError
object. Use this option with gulp.watch
to keep gulp from stopping every time you mess up your sass.
onSuccess: callback
Pass in your own callback to be called upon successful compilation by node-sass. The callback has the form callback(css)
, and is passed the compiled css as a string. Note: This does not prevent gulp-sass's default behavior of writing the output css file.
onError: callback
Pass in your own callback to be called upon a sass error from node-sass. The callback has the form callback(err)
, where err is the error string generated by libsass. Note: this does prevent an actual gulpPluginError
object from being created.
sync: true
If you pass sync: true
into the options hash, sass.renderSync will be called, instead of sass.render. This should help when memory and/or cpu usage is getting very high when rendering many and/or big files.
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 the gulp-sass compiler and write the source maps after.
var sourcemaps = require('gulp-sourcemaps');
gulp.src('./scss/*.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(sourcemaps.write())
.pipe('./css');
// will write the source maps inline in the compiled CSS files
By default, gulp-sourcemaps writes the source maps inline in the compiled CSS files. To write them to a separate file, specify a relative file path in the sourcemaps.write()
function.
var sourcemaps = require('gulp-sourcemaps');
gulp.src('./scss/*.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(sourcemaps.write('./maps'))
.pipe('./css');
// will write the source maps to ./dest/css/maps
#Imports and Partials
gulp-sass now automatically passes along the directory of every scss file it parses as an include path for node-sass. This means that as long as you specify your includes relative to path of your scss file, everything will just work.
scss/includes/_settings.scss:
$blue: #3bbfce;
$margin: 16px;
scss/style.scss:
@import "includes/settings";
.content-navigation {
border-color: $blue;
color:
darken($blue, 9%);
}
.border {
padding: $margin / 2;
margin: $margin / 2;
border-color: $blue;
}
FAQs
Gulp plugin for sass
The npm package gulp-sass receives a total of 225,809 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.