Gulp-sass: LoadPath Documentation

Created on 7 Aug 2017  路  4Comments  路  Source: dlmanning/gulp-sass

Please include documentation on how to load node_modules paths using gulp.sass

Most helpful comment

you could do it like this:

var path = require("path");

function importer(url, prev, done) {
    if (url[0] === '~') {
        url = path.resolve('./node_modules', url.substr(1));
    }

    return { file: url };
}

gulp.task('scss',function() {
    return gulp.src('app/style.scss')
    .pipe(sass({importer:importer}))
    .pipe(gulp.dest('dist'));
});

All 4 comments

I'm having this exact same issue!

gulp.task('sass', function(){
  return gulp.src('./node_modules/foundation-sites/scss/foundation.scss')
    .pipe(
        sass(
            {
                includePaths: [
                    './node_modules/foundation-sites/scss/',
                ]
            }
        )
    )
    .pipe(gulp.dest('./app/resources/css/'));
});

Does not work. Gulp-sass completely ignores the includes. Either I'm doing this wrong, or gulp-sass is broken right now.

you could do it like this:

var path = require("path");

function importer(url, prev, done) {
    if (url[0] === '~') {
        url = path.resolve('./node_modules', url.substr(1));
    }

    return { file: url };
}

gulp.task('scss',function() {
    return gulp.src('app/style.scss')
    .pipe(sass({importer:importer}))
    .pipe(gulp.dest('dist'));
});

This is not possible with gulp-sass or node-sass in a safe manner. I suggesting looking a custom loader for this purpose. I suggest eyeglass. The solutions offered are naive but will work good enough in most case.

Thanks @azerafati,
Now I'm able to resolve the same path in my webpack and gulp builds without having to rewrite any file paths!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sstikkel picture sstikkel  路  8Comments

kiki-le-singe picture kiki-le-singe  路  6Comments

webchaz picture webchaz  路  3Comments

Mr-Zafar picture Mr-Zafar  路  6Comments

EpicOkapi picture EpicOkapi  路  5Comments