Removing gulp.src files after gulp.dest?

I have a scenario where my client wants to dump LESS files to a directory src(via FTP), and for them is automatically output as CSS to a directory build. For each LESS file, after creating its CSS file, it should be removed from the directory src. How to do it with gulp?

My current gulpfile.js:

var gulp = require("gulp");
var watch = require("gulp-watch");
var less = require("gulp-less");

watch({ glob: "./src/**/*.less" })
  .pipe(less())
  .pipe(gulp.dest("./build"));

This successfully detects new LESS files that are deleted in the directory srcand outputs the CSS files to build. But after that, it does not clear the LESS files .: (

+4
source share
2 answers

Use gulp-clean.

src, . , , , , .


, gulp-clean gulp.dest, - , , .

var gulp = require('gulp'),
    less = require('gulp-less'),
    clean = require('gulp-clean');

gulp.task('compile-less-cfg', function() {
    return gulp.src('your/less/directory/*.less')
               .pipe(less())
               .pipe('your/build/directory'));
});

gulp.task('remove-less', ['less'], function(){
    return gulp.src('your/less/directory)
               .pipe(clean());
});

. watch *.less , less remove-less. ? - .

remove-less, less. , , , .

, , , . .

+2

gulp-clean . npm del.

npm install --save-dev del

, .

var gulp = require('gulp');
var del = require('del');

gulp.task('clean:mobile', function () {
  return del([
    'dist/report.csv',
    // here we use a globbing pattern to match everything inside the `mobile` folder
    'dist/mobile/**/*',
    // we don't want to clean this file though so we negate the pattern
    '!dist/mobile/deploy.json'
  ]);
});

gulp.task('default', ['clean:mobile']);
+2

Source: https://habr.com/ru/post/1542636/


All Articles