Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

303
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda