Gulp - compile sass by folder, and modify parent directories

前端 未结 1 543
面向向阳花
面向向阳花 2021-01-27 11:13

I\'m new on gulpfile and i can\'t figure out how can I iterate through multiple folders using a single task

My src folder structure

folder1
   assets
           


        
相关标签:
1条回答
  • 2021-01-27 11:42

    Try this:

    const gulp = require("gulp");
    const sass = require("gulp-sass");
    const flatten = require('gulp-flatten');
    
    
    gulp.task('default', function () {
    
      return gulp.src("src/**/assets/style.scss")
        .pipe(sass())
    
          // flatten subPath(0, -1) will strip off the last folder, i.e., 'assets'
          // extracts the first element through the second-to-last element in the sequence.
          // so subfolder1/assets -> subfolder1  (the second-to-last element is subfolder1)
          // and assets/ -> nothing (since there is no second-to-last element!!)
    
        .pipe(flatten({ subPath: [0, -1] }))
    
        .pipe(gulp.dest("dist/"));
    });
    

    gulp-flatten

    0 讨论(0)
提交回复
热议问题