gulp-sass
Advanced tools
Comparing version 2.3.2 to 5.0.0
# Gulp Sass Changelog | ||
## v5.0.0 | ||
**June 25, 2021** | ||
https://github.com/dlmanning/gulp-sass/releases/tag/v5.0.0 | ||
## v4.1.1 | ||
**June 24, 2021** | ||
https://github.com/dlmanning/gulp-sass/releases/tag/v4.1.1 | ||
## v4.1.0 | ||
**April 23, 2020** | ||
https://github.com/dlmanning/gulp-sass/releases/tag/v4.1.0 | ||
## v4.0.2 | ||
**October 16, 2018** | ||
https://github.com/dlmanning/gulp-sass/releases/tag/v4.0.2 | ||
## v4.0.1 | ||
**Apr 8, 2018** | ||
https://github.com/dlmanning/gulp-sass/releases/tag/v4.0.1 | ||
## v4.0.0 | ||
**April 5, 2018** | ||
https://github.com/dlmanning/gulp-sass/releases/tag/v4.0.0 | ||
## v3.2.1 | ||
**March 24, 2018** | ||
https://github.com/dlmanning/gulp-sass/releases/tag/v3.2.1 | ||
## v3.2.0 | ||
**March 12, 2018** | ||
https://github.com/dlmanning/gulp-sass/releases/tag/v3.2.0 | ||
## v3.1.0 | ||
**January 9, 2017** | ||
https://github.com/dlmanning/gulp-sass/releases/tag/v3.1.0 | ||
## v3.0.0 | ||
**January 9, 2017** | ||
https://github.com/dlmanning/gulp-sass/releases/tag/v3.0.0 | ||
## v2.3.2 | ||
**June 15, 2016** | ||
https://github.com/dlmanning/gulp-sass/releases/tag/v2.3.2 | ||
## v2.3.1 | ||
**April 22, 2016** | ||
https://github.com/dlmanning/gulp-sass/releases/tag/v2.3.1 | ||
## v2.3.0 | ||
**April 21, 2016** | ||
https://github.com/dlmanning/gulp-sass/releases/tag/v2.3.0 | ||
## v2.3.0-beta.1 | ||
**February 4, 2016** | ||
https://github.com/dlmanning/gulp-sass/releases/tag/v2.3.0-beta.1 | ||
## v2.2.0 | ||
**February 4, 2016** | ||
https://github.com/dlmanning/gulp-sass/releases/tag/v2.2.0 | ||
## v2.1.0 | ||
**November 2, 2015** | ||
https://github.com/dlmanning/gulp-sass/releases/tag/v2.1.0 | ||
## v2.1.0-beta | ||
@@ -4,0 +82,0 @@ **September 21, 2015** |
# Contributing to Gulp Sass | ||
Gulp Sass is a very light-weight [Gulp](https://github.com/gulpjs/gulp) wrapper for [`node-sass`](https://github.com/sass/node-sass), which in turn is a Node binding for [`libsass`](https://github.com/sass/libsass), which in turn is a port of [`Sass`](https://github.com/sass/sass). | ||
`gulp-sass` is a very light-weight wrapper around either [Dart Sass][] or [Node Sass][] (which in turn is a Node binding for [LibSass][]. All of these are implementations of the [Sass][] language. | ||
[Dart Sass]: http://sass-lang.com/dart-sass | ||
[Node Sass]: https://github.com/sass/node-sass | ||
[LibSass]: https://sass-lang.com/libsass | ||
[Sass]: https://sass-lang.com | ||
## Submitting Issues | ||
* Before creating a new issue, perform a [cursory search](https://github.com/issues?utf8=%E2%9C%93&q=repo%3Adlmanning%2Fgulp-sass+repo%3Asass%2Fnode-sass+repo%3Asass%2Flibsass+repo%3Asass%2Fsass+repo%3Asass-eyeglass%2Feyeglass) in the Gulp Sass, Node Sass, Libsass, and main Sass repos to see if a similar issue has already been submitted. Please also refer to our [Common Issues and Their Fixes](https://github.com/dlmanning/gulp-sass/wiki/Common-Issues-and-Their-Fixes) page for some basic troubleshooting. | ||
* Before creating a new issue, perform a [cursory search](https://github.com/issues?utf8=%E2%9C%93&q=repo%3Adlmanning%2Fgulp-sass+repo%3Asass%2Fdart-sass+repo%3Asass%2Fnode-sass+repo%3Asass%2Flibsass+repo%3Asass%2Fsass+repo%3Asass-eyeglass%2Feyeglass) in the Gulp Sass, Dart Sass, Node Sass, Libsass, and main Sass repos to see if a similar issue has already been submitted. Please also refer to our [Common Issues and Their Fixes](https://github.com/dlmanning/gulp-sass/wiki/Common-Issues-and-Their-Fixes) page for some basic troubleshooting. | ||
* You can create an issue [here](https://github.com/dlmanning/gulp-sass/issues). Please include as many details as possible in your report. | ||
@@ -63,2 +68,2 @@ * Issue titles should be descriptive, explaining at the high level what it is about. | ||
* :shirt: `:shirt:` when removing linter warnings | ||
* :shipit: `:shipit:` when creating a new release | ||
* :shipit: `:shipit:` when creating a new release |
295
index.js
@@ -1,189 +0,180 @@ | ||
'use strict'; | ||
const chalk = require('chalk'); | ||
const PluginError = require('plugin-error'); | ||
const replaceExtension = require('replace-ext'); | ||
const stripAnsi = require('strip-ansi'); | ||
const transfob = require('transfob'); | ||
const clonedeep = require('lodash/cloneDeep'); | ||
const path = require('path'); | ||
const applySourceMap = require('vinyl-sourcemaps-apply'); | ||
var gutil = require('gulp-util'); | ||
var through = require('through2'); | ||
var clonedeep = require('lodash.clonedeep'); | ||
var path = require('path'); | ||
var applySourceMap = require('vinyl-sourcemaps-apply'); | ||
const PLUGIN_NAME = 'gulp-sass'; | ||
var PLUGIN_NAME = 'gulp-sass'; | ||
////////////////////////////// | ||
/// /////////////////////////// | ||
// Main Gulp Sass function | ||
////////////////////////////// | ||
var gulpSass = function gulpSass(options, sync) { | ||
return through.obj(function(file, enc, cb) { | ||
var opts, | ||
filePush, | ||
errorM, | ||
callback, | ||
result; | ||
/// /////////////////////////// | ||
const gulpSass = (options, sync) => transfob((file, enc, cb) => { // eslint-disable-line consistent-return | ||
if (file.isNull()) { | ||
return cb(null, file); | ||
} | ||
if (file.isNull()) { | ||
return cb(null, file); | ||
} | ||
if (file.isStream()) { | ||
return cb(new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported')); | ||
} | ||
if (path.basename(file.path).indexOf('_') === 0) { | ||
return cb(); | ||
} | ||
if (!file.contents.length) { | ||
file.path = gutil.replaceExtension(file.path, '.css'); | ||
return cb(null, file); | ||
} | ||
if (file.isStream()) { | ||
return cb(new PluginError(PLUGIN_NAME, 'Streaming not supported')); | ||
} | ||
if (path.basename(file.path).indexOf('_') === 0) { | ||
return cb(); | ||
} | ||
opts = clonedeep(options || {}); | ||
opts.data = file.contents.toString(); | ||
if (!file.contents.length) { | ||
file.path = replaceExtension(file.path, '.css'); // eslint-disable-line no-param-reassign | ||
return cb(null, file); | ||
} | ||
// we set the file path here so that libsass can correctly resolve import paths | ||
opts.file = file.path; | ||
const opts = clonedeep(options || {}); | ||
opts.data = file.contents.toString(); | ||
// Ensure `indentedSyntax` is true if a `.sass` file | ||
if (path.extname(file.path) === '.sass') { | ||
opts.indentedSyntax = true; | ||
} | ||
// we set the file path here so that libsass can correctly resolve import paths | ||
opts.file = file.path; | ||
// Ensure file's parent directory in the include path | ||
if (opts.includePaths) { | ||
if (typeof opts.includePaths === 'string') { | ||
opts.includePaths = [opts.includePaths]; | ||
} | ||
// Ensure `indentedSyntax` is true if a `.sass` file | ||
if (path.extname(file.path) === '.sass') { | ||
opts.indentedSyntax = true; | ||
} | ||
// Ensure file's parent directory in the include path | ||
if (opts.includePaths) { | ||
if (typeof opts.includePaths === 'string') { | ||
opts.includePaths = [opts.includePaths]; | ||
} | ||
else { | ||
opts.includePaths = []; | ||
} | ||
} else { | ||
opts.includePaths = []; | ||
} | ||
opts.includePaths.unshift(path.dirname(file.path)); | ||
opts.includePaths.unshift(path.dirname(file.path)); | ||
// Generate Source Maps if plugin source-map present | ||
if (file.sourceMap) { | ||
opts.sourceMap = file.path; | ||
opts.omitSourceMapUrl = true; | ||
opts.sourceMapContents = true; | ||
} | ||
// Generate Source Maps if plugin source-map present | ||
if (file.sourceMap) { | ||
opts.sourceMap = file.path; | ||
opts.omitSourceMapUrl = true; | ||
opts.sourceMapContents = true; | ||
} | ||
////////////////////////////// | ||
// Handles returning the file to the stream | ||
////////////////////////////// | ||
filePush = function filePush(sassObj) { | ||
var sassMap, | ||
sassMapFile, | ||
sassFileSrc, | ||
sassFileSrcPath, | ||
sourceFileIndex; | ||
/// /////////////////////////// | ||
// Handles returning the file to the stream | ||
/// /////////////////////////// | ||
const filePush = (sassObj) => { | ||
let sassMap; | ||
let sassMapFile; | ||
let sassFileSrc; | ||
let sassFileSrcPath; | ||
let sourceFileIndex; | ||
// Build Source Maps! | ||
if (sassObj.map) { | ||
// Transform map into JSON | ||
sassMap = JSON.parse(sassObj.map.toString()); | ||
// Grab the stdout and transform it into stdin | ||
sassMapFile = sassMap.file.replace(/^stdout$/, 'stdin'); | ||
// Grab the base file name that's being worked on | ||
sassFileSrc = file.relative; | ||
// Grab the path portion of the file that's being worked on | ||
sassFileSrcPath = path.dirname(sassFileSrc); | ||
if (sassFileSrcPath) { | ||
//Prepend the path to all files in the sources array except the file that's being worked on | ||
sourceFileIndex = sassMap.sources.indexOf(sassMapFile); | ||
sassMap.sources = sassMap.sources.map(function(source, index) { | ||
return (index === sourceFileIndex) ? source : path.join(sassFileSrcPath, source); | ||
}); | ||
} | ||
// Remove 'stdin' from souces and replace with filenames! | ||
sassMap.sources = sassMap.sources.filter(function(src) { | ||
if (src !== 'stdin') { | ||
return src; | ||
} | ||
// Build Source Maps! | ||
if (sassObj.map) { | ||
// Transform map into JSON | ||
sassMap = JSON.parse(sassObj.map.toString()); | ||
// Grab the stdout and transform it into stdin | ||
sassMapFile = sassMap.file.replace(/^stdout$/, 'stdin'); | ||
// Grab the base file name that's being worked on | ||
sassFileSrc = file.relative; | ||
// Grab the path portion of the file that's being worked on | ||
sassFileSrcPath = path.dirname(sassFileSrc); | ||
if (sassFileSrcPath) { | ||
// Prepend the path to all files in the sources array except the file that's being worked on | ||
sourceFileIndex = sassMap.sources.indexOf(sassMapFile); | ||
sassMap.sources = sassMap.sources.map((source, index) => { // eslint-disable-line arrow-body-style | ||
return index === sourceFileIndex ? source : path.join(sassFileSrcPath, source); | ||
}); | ||
// Replace the map file with the original file name (but new extension) | ||
sassMap.file = gutil.replaceExtension(sassFileSrc, '.css'); | ||
// Apply the map | ||
applySourceMap(file, sassMap); | ||
} | ||
file.contents = sassObj.css; | ||
file.path = gutil.replaceExtension(file.path, '.css'); | ||
// Remove 'stdin' from souces and replace with filenames! | ||
sassMap.sources = sassMap.sources.filter((src) => src !== 'stdin' && src); | ||
cb(null, file); | ||
}; | ||
// Replace the map file with the original file name (but new extension) | ||
sassMap.file = replaceExtension(sassFileSrc, '.css'); | ||
// Apply the map | ||
applySourceMap(file, sassMap); | ||
} | ||
////////////////////////////// | ||
// Handles error message | ||
////////////////////////////// | ||
errorM = function errorM(error) { | ||
var relativePath = '', | ||
filePath = error.file === 'stdin' ? file.path : error.file, | ||
message = ''; | ||
file.contents = sassObj.css; // eslint-disable-line no-param-reassign | ||
file.path = replaceExtension(file.path, '.css'); // eslint-disable-line no-param-reassign | ||
filePath = filePath ? filePath : file.path; | ||
relativePath = path.relative(process.cwd(), filePath); | ||
if (file.stat) { | ||
file.stat.atime = file.stat.mtime = file.stat.ctime = new Date(); // eslint-disable-line | ||
} | ||
message += gutil.colors.underline(relativePath) + '\n'; | ||
message += error.formatted; | ||
cb(null, file); | ||
}; | ||
error.messageFormatted = message; | ||
error.messageOriginal = error.message; | ||
error.message = gutil.colors.stripColor(message); | ||
/// /////////////////////////// | ||
// Handles error message | ||
/// /////////////////////////// | ||
const errorM = (error) => { | ||
const filePath = (error.file === 'stdin' ? file.path : error.file) || file.path; | ||
const relativePath = path.relative(process.cwd(), filePath); | ||
const message = [chalk.underline(relativePath), error.formatted].join('\n'); | ||
error.relativePath = relativePath; | ||
error.messageFormatted = message; // eslint-disable-line no-param-reassign | ||
error.messageOriginal = error.message; // eslint-disable-line no-param-reassign | ||
error.message = stripAnsi(message); // eslint-disable-line no-param-reassign | ||
error.relativePath = relativePath; // eslint-disable-line no-param-reassign | ||
return cb(new gutil.PluginError( | ||
PLUGIN_NAME, error | ||
)); | ||
}; | ||
return cb(new PluginError(PLUGIN_NAME, error)); | ||
}; | ||
if (sync !== true) { | ||
////////////////////////////// | ||
// Async Sass render | ||
////////////////////////////// | ||
callback = function(error, obj) { | ||
if (error) { | ||
return errorM(error); | ||
} | ||
filePush(obj); | ||
}; | ||
gulpSass.compiler.render(opts, callback); | ||
} | ||
else { | ||
////////////////////////////// | ||
// Sync Sass render | ||
////////////////////////////// | ||
try { | ||
result = gulpSass.compiler.renderSync(opts); | ||
filePush(result); | ||
} | ||
catch (error) { | ||
if (sync !== true) { | ||
/// /////////////////////////// | ||
// Async Sass render | ||
/// /////////////////////////// | ||
const callback = (error, obj) => { // eslint-disable-line consistent-return | ||
if (error) { | ||
return errorM(error); | ||
} | ||
filePush(obj); | ||
}; | ||
gulpSass.compiler.render(opts, callback); | ||
} else { | ||
/// /////////////////////////// | ||
// Sync Sass render | ||
/// /////////////////////////// | ||
try { | ||
filePush(gulpSass.compiler.renderSync(opts)); | ||
} catch (error) { | ||
return errorM(error); | ||
} | ||
}); | ||
}; | ||
} | ||
}); | ||
////////////////////////////// | ||
/// /////////////////////////// | ||
// Sync Sass render | ||
////////////////////////////// | ||
gulpSass.sync = function sync(options) { | ||
return gulpSass(options, true); | ||
}; | ||
/// /////////////////////////// | ||
gulpSass.sync = (options) => gulpSass(options, true); | ||
////////////////////////////// | ||
/// /////////////////////////// | ||
// Log errors nicely | ||
////////////////////////////// | ||
/// /////////////////////////// | ||
gulpSass.logError = function logError(error) { | ||
var message = new gutil.PluginError('sass', error.messageFormatted).toString(); | ||
process.stderr.write(message + '\n'); | ||
const message = new PluginError('sass', error.messageFormatted).toString(); | ||
process.stderr.write(`${message}\n`); | ||
this.emit('end'); | ||
}; | ||
////////////////////////////// | ||
// Store compiler in a prop | ||
////////////////////////////// | ||
gulpSass.compiler = require('node-sass'); | ||
module.exports = (compiler) => { | ||
if (!compiler || !compiler.render) { | ||
const message = new PluginError( | ||
PLUGIN_NAME, | ||
'\n' | ||
+ 'gulp-sass 5 does not have a default Sass compiler; please set one yourself.\n' | ||
+ 'Both the `sass` and `node-sass` packages are permitted.\n' | ||
module.exports = gulpSass; | ||
+ 'For example, in your gulpfile:\n\n' | ||
+ ' var sass = require(\'gulp-sass\')(require(\'sass\'));\n', | ||
{ showProperties: false }, | ||
).toString(); | ||
process.stderr.write(`${message}\n`); | ||
process.exit(1); | ||
} | ||
gulpSass.compiler = compiler; | ||
return gulpSass; | ||
}; |
{ | ||
"name": "gulp-sass", | ||
"version": "2.3.2", | ||
"version": "5.0.0", | ||
"description": "Gulp plugin for sass", | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha test" | ||
"test": "mocha test" | ||
}, | ||
@@ -24,20 +27,27 @@ "repository": { | ||
"dependencies": { | ||
"gulp-util": "^3.0", | ||
"lodash.clonedeep": "^4.3.2", | ||
"node-sass": "^3.4.2", | ||
"through2": "^2.0.0", | ||
"vinyl-sourcemaps-apply": "^0.2.0" | ||
"chalk": "^4.1.1", | ||
"lodash": "^4.17.20", | ||
"plugin-error": "^1.0.1", | ||
"replace-ext": "^2.0.0", | ||
"strip-ansi": "^6.0.0", | ||
"transfob": "^1.0.0", | ||
"vinyl-sourcemaps-apply": "^0.2.1" | ||
}, | ||
"devDependencies": { | ||
"autoprefixer-core": "^5.2.1", | ||
"eslint": "^2.9.0", | ||
"globule": "^1.0.0", | ||
"gulp": "^3.8.11", | ||
"gulp-postcss": "^5.1.10", | ||
"gulp-sourcemaps": "^1.5.2", | ||
"gulp-tap": "^0.1.3", | ||
"mocha": "^2.2.1", | ||
"rimraf": "^2.4.3", | ||
"should": "^8.3.1" | ||
"autoprefixer": "^10.2.6", | ||
"eslint": "^7.28.0", | ||
"eslint-config-airbnb-base": "^14.2.1", | ||
"eslint-plugin-import": "^2.23.4", | ||
"globule": "^1.3.2", | ||
"gulp": "^4.0.2", | ||
"gulp-postcss": "^9.0.0", | ||
"gulp-sourcemaps": "^3.0.0", | ||
"gulp-tap": "^2.0.0", | ||
"mocha": "^9.0.0", | ||
"node-sass": "^6.0.0", | ||
"postcss": "^8.3.4", | ||
"rimraf": "^3.0.2", | ||
"should": "^13.2.3", | ||
"vinyl": "^2.2.1" | ||
} | ||
} |
172
README.md
@@ -1,17 +0,37 @@ | ||
# gulp-sass [![Build Status](https://travis-ci.org/dlmanning/gulp-sass.svg?branch=master)](https://travis-ci.org/dlmanning/gulp-sass) [![Join the chat at https://gitter.im/dlmanning/gulp-sass](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dlmanning/gulp-sass?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![npm version](https://badge.fury.io/js/gulp-sass.svg)](http://badge.fury.io/js/gulp-sass) | ||
# gulp-sass ![Build status](https://img.shields.io/travis/dlmanning/gulp-sass) [![Join the chat at https://gitter.im/dlmanning/gulp-sass](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dlmanning/gulp-sass?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) ![Node support](https://img.shields.io/node/v/gulp-sass) ![NPM package version](https://img.shields.io/npm/v/gulp-sass?label=npm%20version) | ||
Sass plugin for [Gulp](https://github.com/gulpjs/gulp). | ||
**_Before filing an issue, please make sure you have [Updated to the latest Gulp Sass](https://github.com/dlmanning/gulp-sass/wiki/Update-to-the-latest-Gulp-Sass) and have gone through our [Common Issues and Their Fixes](https://github.com/dlmanning/gulp-sass/wiki/Common-Issues-and-Their-Fixes) section._** | ||
**_Before filing an issue, please make sure you have [updated to the latest version of `gulp-sass`](https://github.com/dlmanning/gulp-sass/wiki/Update-to-the-latest-Gulp-Sass) and have gone through our [Common Issues and Their Fixes](https://github.com/dlmanning/gulp-sass/wiki/Common-Issues-and-Their-Fixes) section._** | ||
# Install | ||
**Migrating your existing project to version 5? Please read our (short!) [migration guide](#migrating-to-version-5).** | ||
## Support | ||
Only [Active LTS and Current releases][1] are supported. | ||
[1]: https://github.com/nodejs/Release#release-schedule | ||
## Installation | ||
To use `gulp-sass`, you must install both `gulp-sass` itself *and* a Sass compiler. `gulp-sass` supports both [Dart Sass][] and [Node Sass][], but Node Sass is [deprecated](https://sass-lang.com/blog/libsass-is-deprecated). We recommend that you use Dart Sass for new projects, and migrate Node Sass projects to Dart Sass when possible. | ||
Whichever compiler you choose, it's best to install these as dev dependencies: | ||
``` | ||
npm install gulp-sass --save-dev | ||
npm install sass gulp-sass --save-dev | ||
``` | ||
# Basic Usage | ||
## Usage | ||
Something like this will compile your Sass files: | ||
**Note:** These examples assume you're using Gulp 4. For examples that work with Gulp 3, [check the docs for an earlier version of `gulp-sass`](https://github.com/dlmanning/gulp-sass/tree/v4.1.1). | ||
`gulp-sass` runs inside of Gulp tasks. No matter what else you do with `gulp-sass`, you must first import it into your gulpfile, making sure to pass it the compiler of your choice. From there, create a Gulp task that calls either `sass()` (to asynchronously render your CSS), or `sass.sync()` (to render it synchronously). Then, export your task with the `export` keyword. We'll show some examples of how to do that. | ||
**⚠️ Note:** With 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()` | ||
### Render your CSS | ||
To render your CSS with a build task, then watch your files for changes, you might write something like this.: | ||
```javascript | ||
@@ -21,85 +41,131 @@ 'use strict'; | ||
var gulp = require('gulp'); | ||
var sass = require('gulp-sass'); | ||
var sass = require('gulp-sass')(require('sass')); | ||
gulp.task('sass', function () { | ||
function buildStyles() { | ||
return gulp.src('./sass/**/*.scss') | ||
.pipe(sass().on('error', sass.logError)) | ||
.pipe(gulp.dest('./css')); | ||
}); | ||
}; | ||
gulp.task('sass:watch', function () { | ||
exports.buildStyles = buildStyles; | ||
exports.watch = function () { | ||
gulp.watch('./sass/**/*.scss', ['sass']); | ||
}); | ||
}; | ||
``` | ||
You can also compile synchronously, doing something like this: | ||
With synchronous rendering, that Gulp task looks like this: | ||
```javascript | ||
'use strict'; | ||
var gulp = require('gulp'); | ||
var sass = require('gulp-sass'); | ||
gulp.task('sass', function () { | ||
``` javascript | ||
function buildStyles() { | ||
return gulp.src('./sass/**/*.scss') | ||
.pipe(sass.sync().on('error', sass.logError)) | ||
.pipe(gulp.dest('./css')); | ||
}); | ||
gulp.task('sass:watch', function () { | ||
gulp.watch('./sass/**/*.scss', ['sass']); | ||
}); | ||
}; | ||
``` | ||
## Options | ||
### Render with options | ||
Pass in options just like you would for [`node-sass`](https://github.com/sass/node-sass#options); they will be passed along just as if you were using `node-sass`. Except for the `data` option which is used by gulp-sass internally. Using the `file` option is also unsupported and results in undefined behaviour that may change without notice. | ||
To change the final output of your CSS, you can pass an options object to your renderer. `gulp-sass` supports [Node Sass's render options](https://github.com/sass/node-sass#options), with two unsupported exceptions: | ||
For example: | ||
- The `data` option, which is used by `gulp-sass` internally. | ||
- The `file` option, which has undefined behavior that may change without notice. | ||
For example, to compress your CSS, you can call `sass({outputStyle: 'compressed'}`. In the context of a Gulp task, that looks like this: | ||
```javascript | ||
gulp.task('sass', function () { | ||
return gulp.src('./sass/**/*.scss') | ||
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError)) | ||
.pipe(gulp.dest('./css')); | ||
}); | ||
function buildStyles() { | ||
return gulp.src('./sass/**/*.scss') | ||
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError)) | ||
.pipe(gulp.dest('./css')); | ||
}; | ||
exports.buildStyles = buildStyles; | ||
``` | ||
## Source Maps | ||
Or this for synchronous rendering: | ||
`gulp-sass` can be used in tandem with [gulp-sourcemaps](https://github.com/floridoo/gulp-sourcemaps) to generate source maps for the Sass to CSS compilation. You will need to initialize [gulp-sourcemaps](https://github.com/floridoo/gulp-sourcemaps) prior to running `gulp-sass` and write the source maps after. | ||
```javascript | ||
function buildStyles() { | ||
return gulp.src('./sass/**/*.scss') | ||
.pipe(sass.sync({outputStyle: 'compressed'}).on('error', sass.logError)) | ||
.pipe(gulp.dest('./css')); | ||
}; | ||
exports.buildStyles = buildStyles; | ||
``` | ||
### Include a source map | ||
`gulp-sass` can be used in tandem with [`gulp-sourcemaps`](https://github.com/floridoo/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. | ||
```javascript | ||
var sourcemaps = require('gulp-sourcemaps'); | ||
gulp.task('sass', function () { | ||
return gulp.src('./sass/**/*.scss') | ||
.pipe(sourcemaps.init()) | ||
.pipe(sass().on('error', sass.logError)) | ||
.pipe(sourcemaps.write()) | ||
.pipe(gulp.dest('./css')); | ||
}); | ||
function buildStyles() { | ||
return gulp.src('./sass/**/*.scss') | ||
.pipe(sourcemaps.init()) | ||
.pipe(sass().on('error', sass.logError)) | ||
.pipe(sourcemaps.write()) | ||
.pipe(gulp.dest('./css')); | ||
} | ||
exports.buildStyles = buildStyles; | ||
``` | ||
By default, [gulp-sourcemaps](https://github.com/floridoo/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. | ||
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. | ||
```javascript | ||
var sourcemaps = require('gulp-sourcemaps'); | ||
gulp.task('sass', function () { | ||
return gulp.src('./sass/**/*.scss') | ||
.pipe(sourcemaps.init()) | ||
.pipe(sass().on('error', sass.logError)) | ||
.pipe(sourcemaps.write('./maps')) | ||
.pipe(gulp.dest('./css')); | ||
}); | ||
function buildStyles() { | ||
return gulp.src('./sass/**/*.scss') | ||
.pipe(sourcemaps.init()) | ||
.pipe(sass().on('error', sass.logError)) | ||
.pipe(sourcemaps.write('./maps')) | ||
.pipe(gulp.dest('./css')); | ||
}; | ||
exports.buildStyles = buildStyles; | ||
``` | ||
# Issues | ||
<h2 id="migrating-to-version-5">Migrating to version 5</h2> | ||
`gulp-sass` is a very light-weight wrapper around [`node-sass`](https://github.com/sass/node-sass), which in turn is a Node binding for [`libsass`](https://github.com/sass/libsass), which in turn is a port of [`Sass`](https://github.com/sass/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. | ||
`gulp-sass` version 5 requires Node 12 or later, and introduces some breaking changes. Additionally, changes in Node itself mean that we should no longer use Node fibers to speed up asynchronous rendering with Dart Sass. | ||
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. | ||
### Setting a Sass compiler | ||
If you're having problems with the options you're passing in, it's likely a `node-sass` or `libsass` issue and you should file your issue with one of those projects. | ||
As of version 5, `gulp-sass` _does not include a default Sass compiler_, so you must install one (either `node-sass` or `sass`) along with `gulp-sass`. | ||
``` | ||
npm 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: | ||
``` diff | ||
- var sass = require('gulp-sass')); | ||
- var compiler = require('sass'); | ||
- sass.compiler = compiler; | ||
+ var sass = require('gulp-sass')(require('sass')); | ||
``` | ||
### 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](https://sass-lang.com/blog/node-fibers-discontinued). The Sass team is exploring its optons 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 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 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. | ||
[Dart Sass]: http://sass-lang.com/dart-sass | ||
[LibSass]: https://sass-lang.com/libsass | ||
[Node Sass]: https://github.com/sass/node-sass | ||
[Sass]: https://sass-lang.com |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
25090
171
7
15
10
153
1
+ Addedchalk@^4.1.1
+ Addedlodash@^4.17.20
+ Addedplugin-error@^1.0.1
+ Addedreplace-ext@^2.0.0
+ Addedstrip-ansi@^6.0.0
+ Addedtransfob@^1.0.0
+ Addedansi-colors@1.1.0(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedarr-diff@4.0.0(transitive)
+ Addedarr-union@3.1.0(transitive)
+ Addedassign-symbols@1.0.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedextend-shallow@3.0.2(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedis-extendable@1.0.1(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedisobject@3.0.1(transitive)
+ Addedplugin-error@1.0.1(transitive)
+ Addedreplace-ext@2.0.0(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedtransfob@1.0.0(transitive)
- Removedgulp-util@^3.0
- Removedlodash.clonedeep@^4.3.2
- Removednode-sass@^3.4.2
- Removedthrough2@^2.0.0
- Removedabbrev@1.1.1(transitive)
- Removedajv@6.12.6(transitive)
- Removedamdefine@1.0.1(transitive)
- Removedansi-gray@0.1.1(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedaproba@1.2.0(transitive)
- Removedare-we-there-yet@1.1.7(transitive)
- Removedarray-differ@1.0.0(transitive)
- Removedarray-find-index@1.0.2(transitive)
- Removedarray-uniq@1.0.3(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasync-foreach@0.1.3(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.0(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedbeeper@1.1.1(transitive)
- Removedblock-stream@0.0.9(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removedcamelcase@2.1.13.0.0(transitive)
- Removedcamelcase-keys@2.1.0(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedchalk@1.1.3(transitive)
- Removedcliui@3.2.0(transitive)
- Removedclone@1.0.4(transitive)
- Removedclone-stats@0.0.1(transitive)
- Removedcode-point-at@1.1.0(transitive)
- Removedcolor-support@1.1.3(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedconsole-control-strings@1.1.0(transitive)
- Removedcore-util-is@1.0.21.0.3(transitive)
- Removedcross-spawn@3.0.1(transitive)
- Removedcurrently-unhandled@0.4.1(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddateformat@2.2.0(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddefine-properties@1.2.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removeddelegates@1.0.0(transitive)
- Removedduplexer2@0.0.2(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfancy-log@1.3.3(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedfind-up@1.1.2(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedfstream@1.0.12(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedgauge@2.7.4(transitive)
- Removedgaze@1.1.3(transitive)
- Removedget-caller-file@1.0.3(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedget-stdin@4.0.1(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedglob@7.1.77.2.3(transitive)
- Removedglobule@1.3.4(transitive)
- Removedglogg@1.0.2(transitive)
- Removedgopd@1.0.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedgulp-util@3.0.8(transitive)
- Removedgulplog@1.0.0(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhas-gulplog@0.1.0(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhas-unicode@2.0.1(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedin-publish@2.0.1(transitive)
- Removedindent-string@2.1.0(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedinvert-kv@1.0.0(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-core-module@2.13.1(transitive)
- Removedis-finite@1.1.0(transitive)
- Removedis-fullwidth-code-point@1.0.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedisarray@0.0.11.0.0(transitive)
- Removedisexe@2.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjs-base64@2.6.4(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedlcid@1.0.0(transitive)
- Removedload-json-file@1.1.0(transitive)
- Removedlodash._basecopy@3.0.1(transitive)
- Removedlodash._basetostring@3.0.1(transitive)
- Removedlodash._basevalues@3.0.0(transitive)
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash._isiterateecall@3.0.9(transitive)
- Removedlodash._reescape@3.0.0(transitive)
- Removedlodash._reevaluate@3.0.0(transitive)
- Removedlodash._reinterpolate@3.0.0(transitive)
- Removedlodash._root@3.0.1(transitive)
- Removedlodash.assign@4.2.0(transitive)
- Removedlodash.clonedeep@4.5.0(transitive)
- Removedlodash.escape@3.2.0(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedlodash.isarray@3.0.4(transitive)
- Removedlodash.keys@3.1.2(transitive)
- Removedlodash.restparam@3.6.1(transitive)
- Removedlodash.template@3.6.2(transitive)
- Removedlodash.templatesettings@3.1.1(transitive)
- Removedloud-rejection@1.6.0(transitive)
- Removedlru-cache@4.1.5(transitive)
- Removedmap-obj@1.0.1(transitive)
- Removedmeow@3.7.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedminimatch@3.0.83.1.2(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removedmultipipe@0.1.2(transitive)
- Removednan@2.19.0(transitive)
- Removednode-gyp@3.8.0(transitive)
- Removednode-sass@3.13.1(transitive)
- Removednopt@3.0.6(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removednpmlog@4.1.2(transitive)
- Removednumber-is-nan@1.0.1(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedobject-assign@3.0.04.1.1(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedobject.assign@4.1.5(transitive)
- Removedonce@1.4.0(transitive)
- Removedos-homedir@1.0.2(transitive)
- Removedos-locale@1.4.0(transitive)
- Removedos-tmpdir@1.0.2(transitive)
- Removedosenv@0.1.5(transitive)
- Removedparse-json@2.2.0(transitive)
- Removedparse-node-version@1.0.1(transitive)
- Removedpath-exists@2.1.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpath-type@1.1.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpify@2.3.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedpseudomap@1.0.2(transitive)
- Removedpsl@1.9.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedread-pkg@1.1.0(transitive)
- Removedread-pkg-up@1.0.1(transitive)
- Removedreadable-stream@1.1.142.3.8(transitive)
- Removedredent@1.0.0(transitive)
- Removedrepeating@2.0.1(transitive)
- Removedreplace-ext@0.0.1(transitive)
- Removedrequest@2.88.2(transitive)
- Removedrequire-directory@2.1.1(transitive)
- Removedrequire-main-filename@1.0.1(transitive)
- Removedresolve@1.22.8(transitive)
- Removedrimraf@2.7.1(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsass-graph@2.2.6(transitive)
- Removedscss-tokenizer@0.2.3(transitive)
- Removedsemver@5.3.0(transitive)
- Removedset-blocking@2.0.0(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedsource-map@0.4.4(transitive)
- Removedsparkles@1.0.1(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.18(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedstring-width@1.0.2(transitive)
- Removedstring_decoder@0.10.311.1.1(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedstrip-indent@1.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedtar@2.2.2(transitive)
- Removedthrough2@2.0.5(transitive)
- Removedtime-stamp@1.1.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtrim-newlines@1.0.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removeduuid@3.4.0(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)
- Removedverror@1.10.0(transitive)
- Removedvinyl@0.5.3(transitive)
- Removedwhich@1.3.1(transitive)
- Removedwhich-module@1.0.0(transitive)
- Removedwide-align@1.1.5(transitive)
- Removedwrap-ansi@2.1.0(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedxtend@4.0.2(transitive)
- Removedy18n@3.2.2(transitive)
- Removedyallist@2.1.2(transitive)
- Removedyargs@7.1.2(transitive)
- Removedyargs-parser@5.0.1(transitive)