A
A
Alexander2019-07-15 16:54:40
gulp.js
Alexander, 2019-07-15 16:54:40

How to customize the output of gulp files?

I have a project structure:

  • /gulpfile.js
  • /source/
  • /dist/

Projects are in the source folder . Each has its own folder.
  • /source/proj1
  • /source/proj2

Question, How to make in gulp that files from source would be output to dist in the same folders with projects. For clarity, it should be like this:
There is /source/ proj1 /assets/sass/main.sass
It is necessary /dist/ proj1 /assets/css/main.min.css

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-07-15
@slpMouse

I solved the problem by digging into the gulp-rename module. You just need to add a function when adding a suffix that will replace the name of the sass folder with css:

gulp.task('sass:compile', function () {
  return gulp.src('./source/**/assets/sass/**/*.sass')
    .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
    .pipe(rename(function(path) {
      path.dirname = path.dirname.replace( "sass", "css" );
      path.basename += '.min';}))
    .pipe(gulp.dest('./dist'))
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question