diff --git a/README.md b/README.md index 056d692..f475da2 100644 --- a/README.md +++ b/README.md @@ -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')); -}); -``` diff --git a/index.js b/index.js index 3d5ca84..6a83761 100644 --- a/index.js +++ b/index.js @@ -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); diff --git a/test/scss/inheritance.scss b/test/scss/inheritance.scss index 053670a..f3caa92 100644 --- a/test/scss/inheritance.scss +++ b/test/scss/inheritance.scss @@ -1,4 +1,4 @@ -@import "cats"; +@import "includes/cats"; .error { border: #f00; diff --git a/test/test.js b/test/test.js index d096c93..3a440dc 100644 --- a/test/test.js +++ b/test/test.js @@ -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');