Skip to content

Commit 64f6444

Browse files
nex3sindresorhus
authored andcommittedJun 27, 2018
Add support for Dart Sass (#283)
1 parent 683ad07 commit 64f6444

File tree

4 files changed

+61
-13
lines changed

4 files changed

+61
-13
lines changed
 

‎gruntfile.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
'use strict';
2+
const sass = require('node-sass');
3+
24
module.exports = grunt => {
35
grunt.initConfig({
46
sass: {
7+
options: {
8+
implementation: sass
9+
},
510
compile: {
611
files: {
712
'test/tmp/compile.css': 'test/fixtures/test.scss',

‎package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@
2828
"preprocess",
2929
"libsass"
3030
],
31-
"dependencies": {
32-
"node-sass": "^4.7.2"
33-
},
3431
"devDependencies": {
3532
"grunt": "^1.0.1",
3633
"grunt-cli": "^1.2.0",
3734
"grunt-contrib-clean": "^1.0.0",
3835
"grunt-contrib-nodeunit": "^1.0.0",
36+
"node-sass": "^4.7.2",
3937
"xo": "*"
4038
},
4139
"peerDependencies": {

‎readme.md

+49-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
# grunt-sass [![Build Status](https://travis-ci.org/sindresorhus/grunt-sass.svg?branch=master)](https://travis-ci.org/sindresorhus/grunt-sass)
22

3-
[<img src="https://rawgit.com/sass/node-sass/master/media/logo.svg" width="150" align="right">](https://github.com/sass/node-sass)
3+
[<img src="https://github.com/sass/sass-site/blob/master/source/assets/img/logos/logo-seal.png" width="150" align="right">](https://sass-lang.com)
44

5-
> Compile Sass to CSS using [node-sass](https://github.com/sass/node-sass)
5+
> Compile Sass to CSS using [Dart Sass][] or [Node Sass][].
66
7-
*The issue tracker is disabled because of continuous abuse. Use [Stack Overflow](https://stackoverflow.com/questions/tagged/node-sass) for support questions. Issues with the output should be reported on the libsass [issue tracker](https://github.com/hcatlin/libsass/issues). Install issues should be reported on the node-sass [issue tracker](https://github.com/sass/node-sass/issues). Learn how [semver works](https://nodesource.com/blog/semver-tilde-and-caret) before opening a PR updating node-sass.*
7+
[Dart Sass]: http://sass-lang.com/dart-sass
8+
[Node Sass]: https://github.com/sass/node-sass
89

9-
This task uses [libsass](http://libsass.org), which is a Sass compiler in C++. It's a lot faster than the original Ruby compiler and [fully compatible](http://sass-compatibility.github.io/).
10+
Before filing an issue with this repository, please consider:
11+
12+
* Asking support questions on Use [Stack Overflow][].
13+
14+
* Reporting issues with the output on the [Dart Sass][Dart Sass issues] or [LibSass][LibSass issues] issue trackers, depending which implementation you're using.
15+
16+
* Reporting installation issues on the [Dart Sass][Dart Sass issues] or [Node Sass][Node Sass issues] issue trackers, depending on which implementation you're using.
17+
18+
[Stack Overflow]: https://stackoverflow.com/questions/tagged/node-sass
19+
[Dart Sass issues]: https://github.com/sass/dart-sass/issues/new
20+
[LibSass issues]: https://github.com/sass/libsass/issues/new
21+
[Node Sass issues]: https://github.com/sass/node-sass/issues/new
1022

1123

1224
## Install
1325

1426
```
15-
$ npm install --save-dev grunt-sass
27+
$ npm install --save-dev node-sass grunt-sass
1628
```
1729

1830
<a href="https://www.patreon.com/sindresorhus">
@@ -23,11 +35,42 @@ $ npm install --save-dev grunt-sass
2335
## Usage
2436

2537
```js
38+
const sass = require('node-sass');
39+
40+
require('load-grunt-tasks')(grunt);
41+
42+
grunt.initConfig({
43+
sass: {
44+
options: {
45+
implementation: sass,
46+
sourceMap: true
47+
},
48+
dist: {
49+
files: {
50+
'main.css': 'main.scss'
51+
}
52+
}
53+
}
54+
});
55+
56+
grunt.registerTask('default', ['sass']);
57+
```
58+
59+
You can choose whether to use [Dart Sass][] or [Node Sass][] by passing the module to the `implementation` option. One implementation or the other *must* be passed.
60+
61+
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:
62+
63+
```js
64+
const Fiber = require('fibers');
65+
const sass = require('node-sass');
66+
2667
require('load-grunt-tasks')(grunt);
2768

2869
grunt.initConfig({
2970
sass: {
3071
options: {
72+
implementation: sass,
73+
fiber: Fiber,
3174
sourceMap: true
3275
},
3376
dist: {
@@ -46,7 +89,7 @@ Files starting with `_` are ignored to match the expected [Sass partial behaviou
4689

4790
## Options
4891

49-
See the `node-sass` [options](https://github.com/sass/node-sass#options), except for `file`, `outFile`, `success`, `error`.
92+
See the Node Sass [options](https://github.com/sass/node-sass#options), except for `file`, `outFile`, `success`, `error`.
5093

5194
The default value for the `precision` option is `10`, so you don't have to change it when using Bootstrap.
5295

‎tasks/sass.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
'use strict';
22
const util = require('util');
33
const path = require('path');
4-
const sass = require('node-sass');
54

65
module.exports = grunt => {
7-
grunt.verbose.writeln(`\n${sass.info}\n`);
8-
96
grunt.registerMultiTask('sass', 'Compile Sass to CSS', async function () {
107
const done = this.async();
118

129
const options = this.options({
1310
precision: 10
1411
});
1512

13+
if (!options.implementation) {
14+
grunt.fatal('The implementation option must be passed to the Sass task.');
15+
}
16+
grunt.verbose.writeln(`\n${options.implementation.info}\n`);
17+
1618
await Promise.all(this.files.map(async item => {
1719
const [src] = item.src;
1820

1921
if (!src || path.basename(src)[0] === '_') {
2022
return;
2123
}
2224

23-
const result = await util.promisify(sass.render)(Object.assign({}, options, {
25+
const result = await util.promisify(options.implementation.render)(Object.assign({}, options, {
2426
file: src,
2527
outFile: item.dest
2628
}));

0 commit comments

Comments
 (0)
Please sign in to comment.