F
F
Fenz2020-06-21 13:09:07
JavaScript
Fenz, 2020-06-21 13:09:07

Why are task modules not included in the main gulpfile?

I'm trying to include files with tasks in the main gulpfile via require-dir, but for some reason it doesn't work. Tell me what am I doing wrong?

const requireDir = require('require-dir');

requireDir('./gulp/tasks/');

module.exports.start = series(scripts, pug2html);`

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
Uncle Tolya, 2020-08-08
@Fenz

Found a solution that I don't like.
But it really works.
You need to wrap the function itself in gulp.task like:

'use strict';

const { src, dest, task } = require('gulp');
const less = require('gulp-less');


task('styles', function () {
  return src('./src/styles/main.less')
    .pipe(less())
    .pipe(dest('./build/css'));

});

and in gulpfile.js start tasks write in the old version:
'use strict';

const { 
  src,
  dest,
  watch,
  series,
  parallel,
  lastRun,
  task } = require('gulp');

const requireDir = require('require-dir');
requireDir('./tasks');

task('default', parallel('html', 'styles'));

Unfortunately, I myself did not understand what this is connected with.

O
Olga, 2020-06-21
@Avilona

can you give a little more details? gulp version? contents of files in tasks? something writes in the console?
apparently, requireDir returns to nowhere and is not processed in any way, you can try to do it like here:
https://github.com/thienhung1989/angular-tree-dnd/...
or do it without require-dir:
gulp.tasks = require('./gulp/tasks/')().tasks;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question