How to use gulp wrench plugin

I studied gulp. I came through the following code.

wrench.readdirSyncRecursive('./gulp').filter(function(file) {
  return (/\.(js|coffee)$/i).test(file);
}).map(function(file) {
  require('./gulp/' + file);
});

Can someone help me understand that the above code is useful?

+4
source share
1 answer

This will load all js or coffee files in the gulp directory to load all gulp tasks, so you don’t have to manually import new gulp tasks, just create anygalleryask.js inside '/ gulp' and you can use it from the command line.

Another advantage of this is that you don't have a huge gulpfile.js with millions of tasks and lines of code, since instead you have anygulptask.js for TASK, it's just good practice because gulpfile grows pretty fast

Gulpfile.js example

 /**
 *  Welcome to your gulpfile!
 *  The gulp tasks are splitted in several files in the gulp directory
 *  because putting all here was really too long
 */

'use strict';

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

/**
 *  This will load all js or coffee files in the gulp directory
 *  in order to load all gulp tasks
 */

wrench.readdirSyncRecursive('./gulp').filter(function (file) {
  return (/\.(js|coffee)$/i).test(file);
}).map(function (file) {
  require('./gulp/' + file);
});


/**
 *  Default task clean temporaries directories and launch the
 *  main optimization build task
 */

gulp.task('default', ['clean'], function () {
  gulp.start('build');
});

YOUR PACKAGE STRUCTURE

gulp/

    build.js
    whatevergulptask.js
    ...
+5
source

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


All Articles