Added: Default for includePaths option

dev
David Manning 2014-01-22 12:52:04 -08:00
parent 137d01d374
commit d009ffb818
4 changed files with 14 additions and 16 deletions

View File

@ -36,7 +36,7 @@ If you pass `errLogToConsole: true` into the options hash, sass errors will be l
#Imports and Partials
If you want to use imports or partials, you'll need to pass the `includePaths` option along to node-sass. So if you have files like this:
gulp-sass now automatically passes along the directory of every scss file it parses as an include path for node-sass. This means that as long as you specify your includes relative to path of your scss file, everything will just work.
scss/includes/_settings.scss:
@ -48,7 +48,7 @@ $margin: 16px;
scss/style.scss:
```scss
@import "settings";
@import "includes/settings";
.content-navigation {
border-color: $blue;
@ -63,12 +63,3 @@ scss/style.scss:
}
```
Your code should look something like this:
```javascript
gulp.task('sass', function () {
gulp.src('./scss/*.scss')
.pipe(sass({includePaths: ['scss/includes']}))
.pipe(gulp.dest('./css'));
});
```

View File

@ -19,6 +19,16 @@ module.exports = function (options) {
opts.data = file.contents.toString();
var fileDir = path.dirname(file.path);
if (opts.includePaths && Array.isArray(opts.includePaths)) {
if (opts.includePaths.indexOf(fileDir) === -1) {
opts.includePaths.push(fileDir)
}
} else {
opts.includePaths = [fileDir];
}
opts.success = function (css) {
file.path = ext(file.path, '.css');
file.contents = new Buffer(css);

View File

@ -1,4 +1,4 @@
@import "cats";
@import "includes/cats";
.error {
border: #f00;

View File

@ -67,10 +67,7 @@ test('compile multiple sass files', function (t) {
];
t.plan(files.length * 4);
var stream = gsass({
includePaths: [path.join(__dirname, 'scss'),
path.join(__dirname, 'scss/includes')]
});
var stream = gsass();
stream.on('data', function (cssFile) {
t.ok(cssFile, 'cssFile exists');