H
H
HelpSophie2020-09-26 13:57:08
JavaScript
HelpSophie, 2020-09-26 13:57:08

How to run a gulp task with a parameter?

I can't figure out how to run the same task with parameters (language selection).

There is a task

// HTML
const html = (lang) => {
  return gulp.src("source/*.html")
    .pipe(rename({suffix: lang}))
    .pipe(gulp.dest("build"));
};
exports.html = html;

and then build, which includes this task

// Build
const build = (done) => gulp.series(
  clean,
  copy,
  styles,
  sprite,
  html(ru),
  html(en),
  js
)(done);
exports.build = build;


But that doesn't work. And I don’t understand how to feed his tongue.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Solntsev, 2020-09-27
@HelpSophie

But the task didn't stop running as Starting 'anonymous'...

Because the function is anonymous.
const html = (lang) => {  // (1)
// 1 - первый вызов происходит, когда вы подключаете таску и передаете ей свои аргументы.
  return () => { // (2)
// 2- эта функция возвращается после передачи аргументов
// и вызывается, когда вы таску запускаете.
// как видите, у нее нет имени.
    return gulp.src("source/*.njk")
      .pipe(rename({suffix: lang}))
      .pipe(gulp.dest("build"));
  };
}
exports.html = html;

const html = (lang) => {
// объявляем функцию
  const html = () => {
    return gulp.src("source/*.njk")
      .pipe(rename({suffix: lang}))
      .pipe(gulp.dest("build"));
  };
  return html;
}
exports.html = html;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question