gulp-sass/README.md

140 lines
4.7 KiB
Markdown
Raw Normal View History

2020-11-05 23:40:12 +01:00
# gulp-sass
2014-01-19 09:50:19 +01:00
2015-03-24 12:32:14 +01:00
Sass plugin for [Gulp](https://github.com/gulpjs/gulp).
2013-09-01 06:54:25 +02:00
2020-11-05 23:40:12 +01:00
This is a fork of [David Manning's Gulp Sass](https://github.com/dlmanning/gulp-sass).
2015-07-22 15:27:21 +02:00
# Support
Only [Active LTS and Current releases][1] are supported.
[1]: https://github.com/nodejs/Release#release-schedule
2015-02-08 18:13:02 +01:00
# Install
2013-09-01 06:54:25 +02:00
```
2020-11-05 23:40:12 +01:00
yarn add --dev sass @selfisekai/gulp-sass
2013-09-01 06:54:25 +02:00
```
2015-02-08 18:13:02 +01:00
# Basic Usage
2013-09-01 06:54:25 +02:00
2015-03-27 00:48:19 +01:00
Something like this will compile your Sass files:
2013-09-01 06:54:25 +02:00
```javascript
2015-05-09 17:06:31 +02:00
'use strict';
2020-11-05 23:40:12 +01:00
const gulp = require('gulp');
const sass = require('@selfisekai/gulp-sass');
2020-11-05 23:40:12 +01:00
sass.compiler = require('sass');
2013-09-01 06:54:25 +02:00
2020-11-05 23:40:12 +01:00
gulp.task('sass', () => {
return gulp.src('./sass/**/*.scss')
2015-05-09 17:06:31 +02:00
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
2020-11-05 23:40:12 +01:00
gulp.task('sass:watch', () => {
2015-05-09 17:06:31 +02:00
gulp.watch('./sass/**/*.scss', ['sass']);
2013-09-01 06:54:25 +02:00
});
```
2015-03-27 00:48:19 +01:00
You can also compile synchronously, doing something like this:
```javascript
2015-05-09 17:06:31 +02:00
'use strict';
2020-11-05 23:40:12 +01:00
const gulp = require('gulp');
const sass = require('@selfisekai/gulp-sass');
2020-11-05 23:40:12 +01:00
sass.compiler = require('sass');
2015-03-27 00:48:19 +01:00
2020-11-05 23:40:12 +01:00
gulp.task('sass', () => {
return gulp.src('./sass/**/*.scss')
2015-03-27 00:48:19 +01:00
.pipe(sass.sync().on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
2015-05-09 17:06:31 +02:00
2020-11-05 23:40:12 +01:00
gulp.task('sass:watch', () => {
2015-05-09 17:06:31 +02:00
gulp.watch('./sass/**/*.scss', ['sass']);
});
2015-03-27 00:48:19 +01:00
```
2020-11-05 23:40:12 +01:00
You can choose whether to use [Dart Sass][] or [Node Sass][] by setting the `sass.compiler` property. Dart 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.
Compiler | Maintained | No installation problems
------------|------------|-------------------------
[Dart Sass] | yes | yes
[Node Sass] | no | no
[Dart Sass]: http://sass-lang.com/dart-sass
[Node Sass]: https://github.com/sass/node-sass
2020-11-05 23:40:12 +01:00
Note that when using Dart Sass, **synchronous compilation is twice as fast as asynchronous compilation** by default, due to the overhead of asynchronous callbacks.
2015-03-24 13:33:23 +01:00
## 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.
For example:
```javascript
2020-11-05 23:40:12 +01:00
gulp.task('sass', () => {
return gulp.src('./sass/**/*.scss')
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
```
Or this for synchronous code:
```javascript
2020-11-05 23:40:12 +01:00
gulp.task('sass', () => {
return gulp.src('./sass/**/*.scss')
.pipe(sass.sync({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
```
2015-03-24 12:32:14 +01:00
## Source Maps
2014-02-11 06:01:45 +01:00
2015-03-24 12:32:14 +01:00
`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.
2014-02-11 06:01:45 +01:00
2014-05-10 21:04:25 +02:00
```javascript
2020-11-05 23:40:12 +01:00
const sourcemaps = require('gulp-sourcemaps');
2014-05-10 21:04:25 +02:00
2020-11-05 23:40:12 +01:00
gulp.task('sass', () => {
return gulp.src('./sass/**/*.scss')
2014-09-24 22:25:39 +02:00
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
2014-05-10 21:04:25 +02:00
.pipe(sourcemaps.write())
2015-01-28 14:45:23 +01:00
.pipe(gulp.dest('./css'));
});
2014-05-10 21:04:25 +02:00
```
2015-03-27 00:50:02 +01:00
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.
2014-05-10 21:04:25 +02:00
```javascript
2020-11-05 23:40:12 +01:00
const sourcemaps = require('gulp-sourcemaps');
gulp.task('sass', () => {
return gulp.src('./sass/**/*.scss')
2014-09-24 22:25:39 +02:00
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
2014-05-10 21:04:25 +02:00
.pipe(sourcemaps.write('./maps'))
2014-11-14 19:02:18 +01:00
.pipe(gulp.dest('./css'));
});
2014-05-10 21:04:25 +02:00
```
2014-02-11 06:01:45 +01:00
2015-02-08 18:13:02 +01:00
# Issues
2014-11-08 19:06:47 +01:00
`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.
[LibSass]: https://sass-lang.com/libsass
[Sass]: https://sass-lang.com
2015-03-24 12:32:14 +01:00
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.
2015-03-24 12:32:14 +01:00
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.
2015-03-24 12:32:14 +01:00
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.