Skip to content

Commit

Permalink
node-sass 2.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 13, 2015
1 parent 88c9b19 commit 335624a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function (grunt) {
},
sourceMap: {
options: {
sourceMap: 'source-map.css.map'
sourceMap: 'test/tmp/source-map.css.map'
},
files: {
'test/tmp/source-map.css': 'test/fixtures/test.scss'
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
"libsass"
],
"dependencies": {
"chalk": "^0.5.1",
"each-async": "^1.0.0",
"node-sass": "2.0.0-beta",
"node-sass": "^2.0.1",
"object-assign": "^2.0.0"
},
"devDependencies": {
Expand Down
40 changes: 3 additions & 37 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

> Compile Sass to CSS using [node-sass](https://github.com/sass/node-sass)
**Issue tracker is temporarily disabled because of user abuse and lazyness. Any issue is most likely with [node-sass](https://github.com/sass/node-sass/issues). Node-sass 2.0 will be used when the final version is out.**

*Issues with the output should be reported on the libsass [issue tracker](https://github.com/hcatlin/libsass/issues).*

This task uses [libsass](http://libsass.org) which is a Sass compiler in C++. In contrast to the original Ruby compiler, this one is much faster, but is [missing some features](http://sass-compatibility.github.io/), though improving quickly. It also doesn't support Compass. Check out [grunt-contrib-sass](https://github.com/gruntjs/grunt-contrib-sass) if you prefer something more stable, but slower.


## Install

```sh
```
$ npm install --save-dev grunt-sass
```

Expand Down Expand Up @@ -44,41 +42,9 @@ Files starting with `_` are ignored to match the expected [Sass partial behaviou

## Options

### includePaths

Type: `array`
Default: `[]`

Additional paths to look for `@import`'ed files.

### outputStyle

Type: `string`
Default: `nested`
Values: `'nested'`, `'compressed'`

Specify the CSS output style.

### imagePath

Type: `string`

Represents the public image path. When using the `image-url()` function in a stylesheet, this path will be prepended to the path you supply. Example: Given an `imagePath` of `/path/to/images`, `background-image: image-url('image.png')` will compile to `background-image: url("/path/to/images/image.png")`.

### sourceMap

Type: `boolean`, `string`
Default: `false`

Set it to `true` to output a Source Map to the same location as the CSS *(output.css.map)*, or specify a path relative to the CSS file to where you want the Source Map.


### precision

Type: `number`
Default: `10`
See the `node-sass` [options](https://github.com/sass/node-sass#options), except for `file`, `outFile`, `success`, `error`.

Number of digits to preserve after the dot. With the number 1.23456789 and a precision of 3, the result will be 1.234 in the final CSS.
The default value for the `precision` option is `10`, so you don't have to change it when using Bootstrap.


## License
Expand Down
31 changes: 16 additions & 15 deletions tasks/sass.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,40 @@
var path = require('path');
var eachAsync = require('each-async');
var assign = require('object-assign');
var chalk = require('chalk');
var sass = require('node-sass');

module.exports = function (grunt) {
grunt.verbose.writeln('\n' + sass.info() + '\n');

grunt.registerMultiTask('sass', 'Compile Sass to CSS', function () {
eachAsync(this.files, function (el, i, next) {
var options = this.options({
var opts = this.options({
precision: 10
});

var src = el.src[0];

if (!src || path.basename(src)[0] === '_') {
return next();
next();
return;
}

sass.render(assign({}, options, {
file: path.resolve(src),
outFile: path.resolve(el.dest),
success: function(results) {
grunt.file.write(el.dest, results.css);
grunt.verbose.writeln('File ' + chalk.cyan(el.dest) + ' created.');
sass.render(assign({}, opts, {
file: src,
outFile: el.dest,
success: function (res) {
grunt.file.write(el.dest, res.css);

if (options.sourceMap) {
var pth = options.sourceMap === true ? (el.dest + '.map') : path.relative(process.cwd(), map);
grunt.verbose.writeln('File ' + chalk.cyan(pth) + ' created.');
if (opts.sourceMap) {
grunt.file.write(opts.sourceMap === true ? (el.dest + '.map') : path.relative(process.cwd(), opts.sourceMap), res.map);
}

next();
},
error: function (error) {
grunt.warn(error.message);
next(error.message);
error: function (err) {
grunt.log.error(err.message + '\n ' + 'Line ' + err.line + ' Column ' + err.column + ' ' + path.relative(process.cwd(), err.file) + '\n');
grunt.warn('');
next(err);
}
}));
}.bind(this), this.async());
Expand Down
2 changes: 0 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ exports.sass = {

test.done();
},
/*
sourceMap: function (test) {
test.expect(2);

Expand All @@ -48,7 +47,6 @@ exports.sass = {
test.ok(/test\.scss/.test(map), 'should include the main file in sourceMap at least');
test.done();
},
*/
sourceMapSimple: function (test) {
test.expect(2);

Expand Down

0 comments on commit 335624a

Please sign in to comment.