Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

306
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda