T
T
Think With Your Head2015-12-18 16:40:25
css
Think With Your Head, 2015-12-18 16:40:25

How to write a task correctly: sass + sourcemaps + many subfolders?

Hello!
Task now looks like this:

gulp.task('sass', function () {
  // bootstrap compilation
  gulp.src('./sass/bootstrap.scss')
  .pipe(sourcemaps.init())
  .pipe(sass())
  .pipe(sourcemaps.write('.', {includeContent: true, sourceRoot: '/sass'}))
  .pipe(gulp.dest('./assets/global/plugins/bootstrap/css/'))

  // global theme stylesheet compilation
  gulp.src('./sass/global/*.scss')
  .pipe(sourcemaps.init())
  .pipe(sass())
  .pipe(sourcemaps.write('.', {includeContent: true, sourceRoot: '/sass/global'}))
  .pipe(gulp.dest('./assets/global/css'))

  gulp.src('./sass/apps/*.scss')
  .pipe(sourcemaps.init())
  .pipe(sass())
  .pipe(sourcemaps.write('.', {includeContent: true, sourceRoot: '/sass/apps'}))
  .pipe(gulp.dest('./assets/apps/css'))

  gulp.src('./sass/pages/*.scss')
  .pipe(sourcemaps.init())
  .pipe(sass())
  .pipe(sourcemaps.write('.', {includeContent: true, sourceRoot: '/sass/pages'}))
  .pipe(gulp.dest('./assets/pages/css'))

  // theme layouts compilation
  gulp.src('./sass/layouts/layout4/*.scss')
  .pipe(sourcemaps.init())
  .pipe(sass())
  .pipe(sourcemaps.write('.', {includeContent: true, sourceRoot: '/sass/layouts/layout4'}))
  .pipe(gulp.dest('./assets/layouts/layout4/css'))

  gulp.src('./sass/layouts/layout4/themes/*.scss')
  .pipe(sourcemaps.init())
  .pipe(sass())
  .pipe(sourcemaps.write('.', {includeContent: true, sourceRoot: '/sass/layouts/layout4/themes'}))
  .pipe(gulp.dest('./assets/layouts/layout4/css/themes'))
});

But something tells me that this code can be simplified several times.
As you can see, there are many sass subfolders and their corresponding dest folders. Also, for sourcemaps to work correctly, you must additionally specify the paths for each source sass folder. And this complicates everything.
But still, how would you do it?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima, 2015-12-24
@Vyad

an array of folder names and sort through for, is it clear or more detailed?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question