Installations
npm install gulp-sass
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=12
Node Version
18.20.2
NPM Version
10.5.0
Score
97.9
Supply Chain
98.5
Quality
79.6
Maintenance
100
Vulnerability
99.6
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (93.76%)
CSS (3.24%)
SCSS (2.71%)
Sass (0.28%)
Developer
dlmanning
Download Statistics
Total Downloads
156,719,323
Last Day
68,365
Last Week
299,135
Last Month
1,326,520
Last Year
18,079,335
GitHub Statistics
1,569 Stars
346 Commits
381 Forks
37 Watching
10 Branches
48 Contributors
Bundle Size
42.84 kB
Minified
13.32 kB
Minified + Gzipped
Package Meta Information
Latest Version
6.0.0
Package Id
gulp-sass@6.0.0
Unpacked Size
23.31 kB
Size
6.56 kB
File Count
5
NPM Version
10.5.0
Node Version
18.20.2
Publised On
27 Nov 2024
Total Downloads
Cumulative downloads
Total Downloads
156,719,323
Last day
-9.7%
68,365
Compared to previous day
Last week
-17.2%
299,135
Compared to previous week
Last month
2.6%
1,326,520
Compared to previous month
Last year
-7.2%
18,079,335
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
gulp-sass
Sass plugin for Gulp.
Before filing an issue, please make sure you have updated to the latest version of gulp-sass
and have gone through our Common Issues and Their Fixes section.
Migrating your existing project to version 5 or 6? Please read our (short!) migration guides.
Support
Only Active LTS and Current releases are supported.
Installation
To use gulp-sass
, you must install both gulp-sass
itself and a Sass compiler. gulp-sass
supports both Embedded Sass, Dart Sass and Node Sass, although Node Sass is deprecated. We recommend that you use Dart Sass for new projects, and migrate Node Sass projects to Dart Sass or Embedded Sass when possible.
Whichever compiler you choose, it's best to install these as dev dependencies:
1npm install sass gulp-sass --save-dev
Importing it into your project
gulp-sass
must be imported into your gulpfile, where you provide it the compiler of your choice. To use gulp-sass
in a CommonJS module (which is most Node.js environments), do something like this:
1const sass = require('gulp-sass')(require('sass'));
To use gulp-sass
in an ECMAScript module (which is supported in newer Node.js 14 and later), do something like this:
1import dartSass from 'sass'; 2import gulpSass from 'gulp-sass'; 3const sass = gulpSass(dartSass);
Usage
Note: These examples are written for CommonJS modules and assume you're using Gulp 4. For examples that work with Gulp 3, check the docs for an earlier version of gulp-sass
.
gulp-sass
must be used in a Gulp task. Your task can call sass()
(to asynchronously render your CSS), or sass.sync()
(to synchronously render your CSS). Then, export your task with the export
keyword. We'll show some examples of how to do that.
⚠️ Note: When using Dart Sass, synchronous rendering is twice as fast as asynchronous rendering. The Sass team is exploring ways to improve asynchronous rendering with Dart Sass, but for now, you will get the best performance from sass.sync()
. If performance is critical, you can use sass-embedded
instead.
Render your CSS
To render your CSS with a build task, then watch your files for changes, you might write something like this:
1'use strict'; 2 3const gulp = require('gulp'); 4const sass = require('gulp-sass')(require('sass')); 5 6function buildStyles() { 7 return gulp.src('./sass/**/*.scss') 8 .pipe(sass().on('error', sass.logError)) 9 .pipe(gulp.dest('./css')); 10}; 11 12exports.buildStyles = buildStyles; 13exports.watch = function () { 14 gulp.watch('./sass/**/*.scss', buildStyles); 15};
With synchronous rendering, that Gulp task looks like this:
1function buildStyles() { 2 return gulp.src('./sass/**/*.scss') 3 .pipe(sass.sync().on('error', sass.logError)) 4 .pipe(gulp.dest('./css')); 5};
Render with options
To change the final output of your CSS, you can pass an options object to your renderer. gulp-sass
supports Sass's JS API compile options, with a few usage notes:
- The
syntax
option is set toindented
automatically for files with the.sass
extension - The
sourceMap
andsourceMapIncludeSources
options are set for you when usinggulp-sourcemaps
For example, to compress your CSS, you can call sass({style: 'compressed'}
. In the context of a Gulp task, that looks like this:
1function buildStyles() { 2 return gulp.src('./sass/**/*.scss') 3 .pipe(sass({style: 'compressed'}).on('error', sass.logError)) 4 .pipe(gulp.dest('./css')); 5}; 6 7exports.buildStyles = buildStyles;
Or this for synchronous rendering:
1function buildStyles() { 2 return gulp.src('./sass/**/*.scss') 3 .pipe(sass.sync({style: 'compressed'}).on('error', sass.logError)) 4 .pipe(gulp.dest('./css')); 5}; 6 7exports.buildStyles = buildStyles;
Include a source map
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
before running gulp-sass
, and write the source maps after.
1const sourcemaps = require('gulp-sourcemaps'); 2 3function buildStyles() { 4 return gulp.src('./sass/**/*.scss') 5 .pipe(sourcemaps.init()) 6 .pipe(sass().on('error', sass.logError)) 7 .pipe(sourcemaps.write()) 8 .pipe(gulp.dest('./css')); 9} 10 11exports.buildStyles = buildStyles;
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.
1const sourcemaps = require('gulp-sourcemaps'); 2 3function buildStyles() { 4 return gulp.src('./sass/**/*.scss') 5 .pipe(sourcemaps.init()) 6 .pipe(sass().on('error', sass.logError)) 7 .pipe(sourcemaps.write('./maps')) 8 .pipe(gulp.dest('./css')); 9}; 10 11exports.buildStyles = buildStyles;
Migrating to version 6
gulp-sass
version 6 uses the new compile function internally by default. If you use any options, for instance custom importers, please compare the new options with the legacy options in order to migrate. For instance, the outputStyle
option is now called style
.
1 function buildStyles() { 2 return gulp.src('./sass/**/*.scss') 3- .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError)) 4+ .pipe(sass({style: 'compressed'}).on('error', sass.logError)) 5 .pipe(gulp.dest('./css')); 6 };
If you want to keep using the legacy API while it's available, you can.
1const sass = require('gulp-sass/legacy')(require('sass'));
If you use source maps, you may see the result change somewhat. The result will typically be absolute file:
URLs, rather than relative ones. The result may also be the source itself, URL encoded. You can optionally add custom importers to adjust the source maps according to your own needs.
Migrating to version 5
gulp-sass
version 5 requires Node.js 12 or later, and introduces some breaking changes. Additionally, changes in Node.js itself mean that Node fibers can no longer be used to speed up Dart Sass in Node.js 16.
Setting a Sass compiler
As of version 5, gulp-sass
does not include a default Sass compiler, so you must install one (either sass
, sass-embedded
, or node-sass
) along with gulp-sass
.
1npm install sass gulp-sass --save-dev
Then, you must explicitly set that compiler in your gulpfille. Instead of setting a compiler
prop on the gulp-sass
instance, you pass the compiler into a function call when instantiating gulp-sass
.
These changes look something like this:
1- const sass = require('gulp-sass')); 2- const compiler = require('sass'); 3- sass.compiler = compiler; 4+ const sass = require('gulp-sass')(require('sass'));
If you're migrating an ECMAScript module, that'll look something like this:
1import dartSass from 'sass'; 2- import sass from 'gulp-sass'; 3- sass.compiler = dartSass; 4 5import dartSass from 'sass'; 6+ import gulpSass from 'gulp-sass'; 7+ const sass = gulpSass(dartSass);
Using the legacy Sass API
If you need to use the deprecated render
Sass API, gulp-sass
still includes legacy support.
1'use strict'; 2 3const gulp = require('gulp'); 4const sass = require('gulp-sass/legacy')(require('sass')); 5 6function buildStyles() { 7 return gulp.src('./sass/**/*.scss') 8 .pipe(sass().on('error', sass.logError)) 9 .pipe(gulp.dest('./css')); 10}; 11 12exports.buildStyles = buildStyles; 13exports.watch = function () { 14 gulp.watch('./sass/**/*.scss', buildStyles); 15};
What about fibers?
We used to recommend Node fibers as a way to speed up asynchronous rendering with Dart Sass. Unfortunately, Node fibers are discontinued and will not work in Node.js 16. The Sass team is exploring its options for future performance improvements, but for now, you will get the best performance from sass.sync()
.
Issues
gulp-sass
is a light-weight wrapper around either Dart Sass or Node Sass (which in turn is a Node.js binding for LibSass. Because of this, the issue you're having likely isn't a gulp-sass
issue, but an issue with one those projects or with Sass as a whole.
If you have a feature request/question about how Sass works/concerns on how your Sass gets compiled/errors in your compiling, it's likely a Dart Sass or LibSass 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 Dart Sass or Node Sass issue 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.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
5 commit(s) and 5 issue activity found in the last 90 days -- score normalized to 8
Reason
Found 25/30 approved changesets -- score normalized to 8
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/dlmanning/gulp-sass/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/dlmanning/gulp-sass/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:50: update your workflow using https://app.stepsecurity.io/secureworkflow/dlmanning/gulp-sass/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:53: update your workflow using https://app.stepsecurity.io/secureworkflow/dlmanning/gulp-sass/ci.yml/master?enable=pin
- Info: 0 out of 4 GitHub-owned GitHubAction dependencies pinned
- Info: 2 out of 2 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 25 are checked with a SAST tool
Reason
21 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-7mwh-4pqv-wmr8
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
Score
4.2
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More