27

I'm reading a tutorial about sass here then I tried some other approach and I cant get the answer in this tutorial. Theres the problem. I have this code in my gulpfile.js

gulp.task('compileNavbar', function() {
    gulp.src('assets/css/sass/**/*.navbar.scss')
        .pipe(sass('navbar.css'))
        .pipe(gulp.dest('assets/css/'));;
});

As of now, I only have assets/css/sass/guest.navbar.scss and this code locates the scss files correctly and puts the output css file in the correct directory BUT the css is named as guest.navbar.css which I didnt expect. I want it to be named as navbar.css but how to?

1
  • I have no experience with Gulp, but have you tried renaming the input file to navbar.scss?
    – Mr Lister
    Sep 12, 2015 at 13:21

1 Answer 1

71

gulp-sass doesn't take any file name parameters. Use gulp-rename to rename your files. If you have more than one .navbar.scss files you want to concatenate into one navbar.css files, feel free to use gulp-concat. This one takes a file name parameter :-)

Install gulp-rename with npm install gulp-rename --save-dev

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

return gulp.src('assets/css/sass/**/*/*.navbar.scss')
   .pipe(sass())
   .pipe(rename('navbar.css'))
   .pipe(gulp.dest('assets/css');

or

Install gulp-concat with npm install gulp-concat --save-dev

var concat = require('gulp-concat');

return gulp.src('assets/css/sass/**/*/*.navbar.scss')
   .pipe(sass())
   .pipe(concat('navbar.css'))
   .pipe(gulp.dest('assets/css');
5
  • Sorry, I forgot to mark this answer as correct. Both methods worked for me. Thanks Oct 18, 2015 at 16:22
  • Hi! I tried the first method and it creates an empty file with the name containing .scss instead of .css. Here is the function I am using: pastebin.com/GJLN5TQG
    – Victor
    May 5, 2016 at 18:58
  • Neither worked for me, until of course I remembered to add gulp-rename pacakge to my dev dependencies ;)
    – S..
    Oct 20, 2016 at 14:28
  • rename doesn't seem to be stable.
    – jgmjgm
    Mar 13, 2019 at 12:10
  • 1
    gulp-concat worked a treat for me. I didn't realise you could effectively concat a single file to a new name.
    – FaCE
    May 1, 2020 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.