Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

304
Views
How to run multiple returns in gulp function?

I'm using the gulp-file-include package to make development locally a little bit easier.

I currently have three HTML pages:

  • index.html
  • contact.html
  • products.html

The way my setup works is:

  • Make .html components in my components folder
  • Include the components on my files located in my template folder
  • gulp watch compiles that template file into HTML and creates / updates the file in the root directory

Folder structure for reference:

theme
   template
      index.html
      contact.html
      product.html
   index.html
   contact.html
   product.html

In short, everything in the template folder contains templating language.

Now, in my gulp I've have to create three different functions to compile the pages when a change for each page is registered.

function compileIndex() {
  return gulp.src('./template/index.html')
    .pipe(fileinclude({
      prefix: '@@',
      basepath: '@file'
    }))
  .pipe(gulp.dest('./'));
}

function compileContact() {
  return gulp.src('./template/contact.html')
    .pipe(fileinclude({
      prefix: '@@',
      basepath: '@file'
    }))
  .pipe(gulp.dest('./'));
}

function compileProducts() {
  return gulp.src('./template/product.html')
    .pipe(fileinclude({
      prefix: '@@',
      basepath: '@file'
    }))
  .pipe(gulp.dest('./'));
}

function watch() {
  gulp.watch([globalCSS,configCSS,themeCSS, componentCSS],mainCSS);
  gulp.watch([globalJS],mainJS);
  gulp.watch([componentJS]);
  gulp.watch('./template/index.html', compileIndex);
  gulp.watch('./template/contact.html', compileContact);
  gulp.watch('./template/product.html', compileProducts);
}

You can tell it'll get really lengthy and hard to manage once more pages are added. As such, is there a way to morph all of these functions into one?

I have tried simply copying the returns into one function, but get a watch task has to be a function error.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!