Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp: How to create a task that compiles multiple SASS files?

Tags:

gulp

I have the following sass task which compiles app.scss to app.css and reloads the page:

gulp.task('sass', function() {
  return gulp.src('./app/app.scss')
    .pipe(sass())
    .pipe(gulp.dest('./app'))
    .pipe(livereload());
});

Now, I want to compile another file, namely ui-toolkit.scss to ui-toolkit.css.

Is this the best way to update the task?

gulp.task('sass', function() {
  gulp.src('./ui-toolkit/ui-toolkit.scss')
    .pipe(sass())
    .pipe(gulp.dest('./ui-toolkit'));

  return gulp.src('./app/app.scss')
    .pipe(sass())
    .pipe(gulp.dest('./app'))
    .pipe(livereload());
});
like image 968
Misha Moroshko Avatar asked Oct 07 '14 04:10

Misha Moroshko


People also ask

How do you use gulp in sass?

Setting up a task Still using the command line, you can install Gulp-sass by running npm install gulp-sass --save-dev . After that, require Gulp-sass in your gulpfile. js. Put var sass = require('gulp-sass'); under the line you required gulp.

What is gulp SCSS?

Gulp is a tool that helps you out with several tasks when it comes to web development. It's often used to do front end tasks like: Spinning up a web server. Reloading the browser automatically whenever a file is saved. Using preprocessors like Sass or LESS.

What is gulp SRC?

The src() and dest() methods are exposed by gulp to interact with files on your computer. src() is given a glob to read from the file system and produces a Node stream. It locates all matching files and reads them into memory to pass through the stream.


1 Answers

Just specify glob(s) that match multiple scss files. These examples assume you want to save the results to same directory as the source file.

Matches every scss file (in node_modules too):

gulp.task('sass', function() {
  return gulp.src('./**/*.scss')
    .pipe(sass())
    .pipe(gulp.dest('.'));
});

Matches scss files in specific dirs:

gulp.task('sass', function() {
  return gulp.src('./{foo,bar}/*.scss')
    .pipe(sass())
    .pipe(gulp.dest('.'));
});

Matches only specific files (base option is needed here for saving to same directory as source file):

gulp.task('sass', function() {
  return gulp.src(['./foo/foo.scss', './bar/bar.scss'], { base: '.' })
    .pipe(sass())
    .pipe(gulp.dest('.'));
});
like image 174
Heikki Avatar answered Oct 12 '22 01:10

Heikki