duxfox-- duxfox-- - 3 months ago 18
Sass (Sass) Question

gulp task copying entire folder

I have the following gulp task:

gulp.task('sassComponents', function() {
return gulp.src('sassComponents/**/mainScss/*.scss')
.pipe(sass({
'sourcemap=none': true,
errLogToConsole: true
})).on('error', notify.onError({
title: "mistake: ",
message: "<%= error.message %>"
}))
.pipe(gulp.dest('public/stylesheets/'));
});


I want it to take the
.scss
file in
sassComponents/**/mainScss/
and put it in
public/stylesheets
(and convert it to
.css
) but its copying the entire folder structure (not just the file):

**/mainScss/sass.scss


the conversion from
.scss
to
.css
is happening correctly, but how do I just get the sass file out, without the rest of the folders that it's in?

Answer

Try the following:

gulp.task('sassComponents', function(){
    return gulp.src('sassComponents/**/mainScss/*.scss', {base: "./"})
    .pipe(sass({
        'sourcemap=none': true,
        errLogToConsole: true
    })).on('error', notify.onError({
        title: "mistake: ",
        message: "<%= error.message %>"
    }))
    .pipe(rename({dirname:''}))
    .pipe(gulp.dest('public/stylesheets/'));
});

EDIT

To use the above code you'll need to install gulp-rename using npm:

npm install --save gulp-rename

And you'll need to declare it as a variable in your gulpfile

var rename = require('gulp-rename');
Comments