Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update doc to Gulp 4 #750

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 34 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ npm install node-sass gulp-sass --save-dev

# Basic Usage

Note: These example work with Gulp 4. For Gulp 3, [check an older version of the doc](https://github.com/dlmanning/gulp-sass/tree/v4.0.2).

Something like this will compile your Sass files:

```javascript
Expand All @@ -28,15 +30,16 @@ var sass = require('gulp-sass');

sass.compiler = require('node-sass');

gulp.task('sass', function () {
function sassTask() {
return gulp.src('./sass/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
};

gulp.task('sass:watch', function () {
exports.sass = sassTask;
exports.watch = function () {
gulp.watch('./sass/**/*.scss', ['sass']);
});
};
```

You can also compile synchronously, doing something like this:
Expand All @@ -49,15 +52,16 @@ var sass = require('gulp-sass');

sass.compiler = require('node-sass');

gulp.task('sass', function () {
function sassTask() {
return gulp.src('./sass/**/*.scss')
.pipe(sass.sync().on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
};

gulp.task('sass:watch', function () {
exports.sass = sassTask;
exports.watch = function () {
gulp.watch('./sass/**/*.scss', ['sass']);
});
};
```

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.
Expand All @@ -76,15 +80,16 @@ var sass = require('gulp-sass');

sass.compiler = require('sass');

gulp.task('sass', function () {
function sassTask() {
return gulp.src('./sass/**/*.scss')
.pipe(sass({fiber: Fiber}).on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
};

gulp.task('sass:watch', function () {
gulp.watch('./sass/**/*.scss', ['sass']);
});
exports.sass = sassTask;
exports.watch = function () {
gulp.watch('./sass/**/*.scss', [sassTask]);
};
```

## Options
Expand All @@ -94,21 +99,25 @@ Pass in options just like you would for [Node Sass](https://github.com/sass/node
For example:

```javascript
gulp.task('sass', function () {
function sassTask() {
return gulp.src('./sass/**/*.scss')
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
};

exports.sass = sassTask;
```

Or this for synchronous code:

```javascript
gulp.task('sass', function () {
function sassTask() {
return gulp.src('./sass/**/*.scss')
.pipe(sass.sync({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
};

exports.sass = sassTask;
```

## Source Maps
Expand All @@ -118,26 +127,30 @@ gulp.task('sass', function () {
```javascript
var sourcemaps = require('gulp-sourcemaps');

gulp.task('sass', function () {
function sassTask() {
return gulp.src('./sass/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./css'));
});
};

exports.sass = sassTask;
```

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.

```javascript
var sourcemaps = require('gulp-sourcemaps');
gulp.task('sass', function () {
function sassTask() {
return gulp.src('./sass/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('./css'));
});
};

exports.sass = sassTask;
```

# Issues
Expand Down