You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Migrate to use the new Sass JS API by default (#846)
* Migrate to use the new Sass JS API by default
Keep the legacy API around, since its removal is still probably a
while from now.
Fixes#837
* Update README for the next major version
Add a migration section, link to relevant Sass documentation, and
add a section about still using the legacy API.
* Update tests to support the new API, sass-embedded
* Prepare changelog entry for the next major version
* Update CHANGELOG.md
---------
Co-authored-by: Michael Mifsud <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+54-10Lines changed: 54 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,15 @@ Sass plugin for [Gulp](https://github.com/gulpjs/gulp).
4
4
5
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._**
6
6
7
-
**Migrating your existing project to version 5? Please read our (short!) [migration guide](#migrating-to-version-5).**
7
+
**Migrating your existing project to version 5 or 6? Please read our (short!) [migration guides](#migrating-to-version-6).**
8
8
9
9
## Support
10
10
11
11
Only [Active LTS and Current releases](https://github.com/nodejs/Release#release-schedule) are supported.
12
12
13
13
## Installation
14
14
15
-
To use `gulp-sass`, you must install both `gulp-sass` itself *and* a Sass compiler. `gulp-sass` supports both [Dart Sass][] and [Node Sass][], although 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.
15
+
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](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 or Embedded Sass when possible.
16
16
17
17
Whichever compiler you choose, it's best to install these as dev dependencies:
`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.
44
44
45
-
**⚠️ 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 `node-sass` instead, but bear in mind that `node-sass` may not support modern Sass features you rely on.
45
+
**⚠️ 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.
46
46
47
47
### Render your CSS
48
48
@@ -78,17 +78,17 @@ function buildStyles() {
78
78
79
79
### Render with options
80
80
81
-
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:
81
+
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](https://sass-lang.com/documentation/js-api/modules#compileString), with a few usage notes:
82
82
83
-
- The `data` option, which is used by `gulp-sass` internally.
84
-
- The `file` option, which has undefined behavior that may change without notice.
83
+
- The `syntax` optionis set to `indented` automatically for files with the `.sass` extension
84
+
- The `sourceMap` and `sourceMapIncludeSources` options are set for you when using `gulp-sourcemaps`
85
85
86
-
For example, to compress your CSS, you can call `sass({outputStyle: 'compressed'}`. In the context of a Gulp task, that looks like this:
86
+
For example, to compress your CSS, you can call `sass({style: 'compressed'}`. In the context of a Gulp task, that looks like this:
<h2id="migrating-to-version-6">Migrating to version 6</h2>
145
+
146
+
`gulp-sass` version 6 uses the new [compile](https://sass-lang.com/documentation/js-api/modules#compileString) function internally by default. If you use any options, for instance custom importers, please compare the [new options](https://sass-lang.com/documentation/js-api/modules#compileString) with the [legacy options](https://sass-lang.com/documentation/js-api/modules#render) in order to migrate. For instance, the `outputStyle` option is now called `style`.
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](https://sass-lang.com/documentation/js-api/interfaces/CompileResult#sourceMap) to adjust the source maps according to your own needs.
164
+
144
165
<h2id="migrating-to-version-5">Migrating to version 5</h2>
145
166
146
167
`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.
147
168
148
169
### Setting a Sass compiler
149
170
150
-
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`.
171
+
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`.
151
172
152
173
```sh
153
174
npm install sass gulp-sass --save-dev
@@ -176,6 +197,28 @@ import dartSass from 'sass';
176
197
+ const sass = gulpSass(dartSass);
177
198
```
178
199
200
+
### Using the legacy Sass API
201
+
202
+
If you need to use the deprecated `render` Sass API, `gulp-sass` still includes legacy support.
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) 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()`.
@@ -190,6 +233,7 @@ If you're having problems with the options you're passing in, it's likely a Dart
190
233
191
234
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.
0 commit comments