Skip to content

Commit 978b8f6

Browse files
mxmasonxzyfer
andauthored
Update to major version 5 (#802)
* Update node-sass to 6.0.0 Also moves node-sass to devDependencies and peerDependencies. This helps prevent dupes and conflicts in packages using gulp-sass * Make mocha test compatible with gulp@4 * Update package version, engines * Remove node-sass as peer dependency * Replace through2 with transfob * Uninstall through2 * Throw error if compiler not set * Fix casing of Sass Co-authored-by: Michael Mifsud <[email protected]> * Use function arg to set compiler, use transfob package * Update test to new API signature * Update package versions * Fix eslint errors * Incorporate previously proposed documentation changes Copied from #694 * Update document outline, apply copyedits * Copyedit: overall clarifications * Call out migration guide, update badges * Document Gulp 4 usage * smol clarification * Copyedit some headings * Yet Another Copyedit™ * Update README.md Co-authored-by: Michael Mifsud <[email protected]>
1 parent 10eae93 commit 978b8f6

File tree

5 files changed

+194
-159
lines changed

5 files changed

+194
-159
lines changed

CONTRIBUTING.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
# Contributing to Gulp Sass
22

3-
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).
3+
`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.
4+
5+
[Dart Sass]: http://sass-lang.com/dart-sass
6+
[Node Sass]: https://github.com/sass/node-sass
7+
[LibSass]: https://sass-lang.com/libsass
8+
[Sass]: https://sass-lang.com
49

510
## Submitting Issues
611

7-
* 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.
12+
* 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.
813
* You can create an issue [here](https://github.com/dlmanning/gulp-sass/issues). Please include as many details as possible in your report.
914
* Issue titles should be descriptive, explaining at the high level what it is about.
1015
* Please include the version of `gulp-sass`, Node, and NPM you are using, as well as what operating system you are having a problem on.
@@ -60,4 +65,4 @@ When creating creating commits or updating the CHANGELOG, please **start** the c
6065
* :arrow_up: `:arrow_up:` when upgrading dependencies
6166
* :arrow_down: `:arrow_down:` when downgrading dependencies
6267
* :shirt: `:shirt:` when removing linter warnings
63-
* :shipit: `:shipit:` when creating a new release
68+
* :shipit: `:shipit:` when creating a new release

README.md

+100-84
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,170 @@
1-
# 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)
1+
# 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)
22

33
Sass plugin for [Gulp](https://github.com/gulpjs/gulp).
44

5-
**_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._**
5+
**_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._**
66

7-
# Support
7+
**Migrating your existing project to version 5? Please read our (short!) [migration guide](#migrating-to-version-5).**
8+
9+
## Support
810

911
Only [Active LTS and Current releases][1] are supported.
1012

1113
[1]: https://github.com/nodejs/Release#release-schedule
1214

13-
# Install
15+
## Installation
16+
17+
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.
18+
19+
Whichever compiler you choose, it's best to install these as dev dependencies:
1420

1521
```
16-
npm install node-sass gulp-sass --save-dev
22+
npm install sass gulp-sass --save-dev
1723
```
1824

19-
# Basic Usage
25+
## Usage
26+
27+
**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).
28+
29+
`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.
30+
31+
**⚠️ 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()`
32+
33+
### Render your CSS
2034

21-
Something like this will compile your Sass files:
35+
To render your CSS with a build task, then watch your files for changes, you might write something like this.:
2236

2337
```javascript
2438
'use strict';
2539

2640
var gulp = require('gulp');
27-
var sass = require('gulp-sass');
41+
var sass = require('gulp-sass')(require('sass'));
2842

29-
sass.compiler = require('node-sass');
30-
31-
gulp.task('sass', function () {
43+
function buildStyles() {
3244
return gulp.src('./sass/**/*.scss')
3345
.pipe(sass().on('error', sass.logError))
3446
.pipe(gulp.dest('./css'));
35-
});
47+
};
3648

37-
gulp.task('sass:watch', function () {
49+
exports.buildStyles = buildStyles;
50+
exports.watch = function () {
3851
gulp.watch('./sass/**/*.scss', ['sass']);
39-
});
52+
};
4053
```
4154

42-
You can also compile synchronously, doing something like this:
43-
44-
```javascript
45-
'use strict';
46-
47-
var gulp = require('gulp');
48-
var sass = require('gulp-sass');
49-
50-
sass.compiler = require('node-sass');
55+
With synchronous rendering, that Gulp task looks like this:
5156

52-
gulp.task('sass', function () {
57+
``` javascript
58+
function buildStyles() {
5359
return gulp.src('./sass/**/*.scss')
5460
.pipe(sass.sync().on('error', sass.logError))
5561
.pipe(gulp.dest('./css'));
56-
});
57-
58-
gulp.task('sass:watch', function () {
59-
gulp.watch('./sass/**/*.scss', ['sass']);
60-
});
62+
};
6163
```
6264

63-
You can choose whether to use [Dart Sass][] or [Node Sass][] by setting the `sass.compiler` property. Node Sass will be used by default, but it's strongly recommended that you set it explicitly for forwards-compatibility in case the default ever changes.
65+
### Render with options
6466

65-
[Dart Sass]: http://sass-lang.com/dart-sass
66-
[Node Sass]: https://github.com/sass/node-sass
67+
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:
6768

68-
Note that when using Dart Sass, **synchronous compilation is twice as fast as asynchronous compilation** by default, due to the overhead of asynchronous callbacks. To avoid this overhead, you can use the [`fibers`](https://www.npmjs.com/package/fibers) package to call asynchronous importers from the synchronous code path. To enable this, pass the `Fiber` class to the `fiber` option:
69+
- The `data` option, which is used by `gulp-sass` internally.
70+
- The `file` option, which has undefined behavior that may change without notice.
71+
72+
For example, to compress your CSS, you can call `sass({outputStyle: 'compressed'}`. In the context of a Gulp task, that looks like this:
6973

7074
```javascript
71-
'use strict';
75+
function buildStyles() {
76+
return gulp.src('./sass/**/*.scss')
77+
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
78+
.pipe(gulp.dest('./css'));
79+
};
7280

73-
var Fiber = require('fibers');
74-
var gulp = require('gulp');
75-
var sass = require('gulp-sass');
81+
exports.buildStyles = buildStyles;
82+
```
7683

77-
sass.compiler = require('sass');
84+
Or this for synchronous rendering:
7885

79-
gulp.task('sass', function () {
86+
```javascript
87+
function buildStyles() {
8088
return gulp.src('./sass/**/*.scss')
81-
.pipe(sass({fiber: Fiber}).on('error', sass.logError))
89+
.pipe(sass.sync({outputStyle: 'compressed'}).on('error', sass.logError))
8290
.pipe(gulp.dest('./css'));
83-
});
91+
};
8492

85-
gulp.task('sass:watch', function () {
86-
gulp.watch('./sass/**/*.scss', ['sass']);
87-
});
93+
exports.buildStyles = buildStyles;
8894
```
8995

90-
## Options
91-
92-
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.
96+
### Include a source map
9397

94-
For example:
98+
`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.
9599

96100
```javascript
97-
gulp.task('sass', function () {
98-
return gulp.src('./sass/**/*.scss')
99-
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
100-
.pipe(gulp.dest('./css'));
101-
});
101+
var sourcemaps = require('gulp-sourcemaps');
102+
103+
function buildStyles() {
104+
return gulp.src('./sass/**/*.scss')
105+
.pipe(sourcemaps.init())
106+
.pipe(sass().on('error', sass.logError))
107+
.pipe(sourcemaps.write())
108+
.pipe(gulp.dest('./css'));
109+
}
110+
111+
exports.buildStyles = buildStyles;
102112
```
103113

104-
Or this for synchronous code:
114+
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.
105115

106116
```javascript
107-
gulp.task('sass', function () {
108-
return gulp.src('./sass/**/*.scss')
109-
.pipe(sass.sync({outputStyle: 'compressed'}).on('error', sass.logError))
110-
.pipe(gulp.dest('./css'));
111-
});
117+
var sourcemaps = require('gulp-sourcemaps');
118+
119+
function buildStyles() {
120+
return gulp.src('./sass/**/*.scss')
121+
.pipe(sourcemaps.init())
122+
.pipe(sass().on('error', sass.logError))
123+
.pipe(sourcemaps.write('./maps'))
124+
.pipe(gulp.dest('./css'));
125+
};
126+
127+
exports.buildStyles = buildStyles;
112128
```
113129

114-
## Source Maps
130+
<h2 id="migrating-to-version-5">Migrating to version 5</h2>
115131

116-
`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.
132+
`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.
117133

118-
```javascript
119-
var sourcemaps = require('gulp-sourcemaps');
134+
### Setting a Sass compiler
120135

121-
gulp.task('sass', function () {
122-
return gulp.src('./sass/**/*.scss')
123-
.pipe(sourcemaps.init())
124-
.pipe(sass().on('error', sass.logError))
125-
.pipe(sourcemaps.write())
126-
.pipe(gulp.dest('./css'));
127-
});
136+
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`.
137+
138+
```
139+
npm install sass gulp-sass --save-dev
128140
```
129141

130-
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.
142+
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`.
131143

132-
```javascript
133-
var sourcemaps = require('gulp-sourcemaps');
134-
gulp.task('sass', function () {
135-
return gulp.src('./sass/**/*.scss')
136-
.pipe(sourcemaps.init())
137-
.pipe(sass().on('error', sass.logError))
138-
.pipe(sourcemaps.write('./maps'))
139-
.pipe(gulp.dest('./css'));
140-
});
144+
These changes look something like this:
145+
146+
``` diff
147+
- var sass = require('gulp-sass'));
148+
- var compiler = require('sass');
149+
- sass.compiler = compiler;
150+
+ var sass = require('gulp-sass')(require('sass'));
141151
```
142152

143-
# Issues
153+
### What about fibers?
144154

145-
`gulp-sass` is a very 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.
155+
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()`.
146156

147-
[LibSass]: https://sass-lang.com/libsass
148-
[Sass]: https://sass-lang.com
157+
## Issues
158+
159+
`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.
149160

150161
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.
151162

152163
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.
153164

154165
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.
166+
167+
[Dart Sass]: http://sass-lang.com/dart-sass
168+
[LibSass]: https://sass-lang.com/libsass
169+
[Node Sass]: https://github.com/sass/node-sass
170+
[Sass]: https://sass-lang.com

0 commit comments

Comments
 (0)