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

370
Visualizações
Gulpfile not compiling Scss & JS properly

I am trying to create a gulpfile.js to compile scss to css and JS components to a main JS file. But it's not working properly.
The issues i am facing, when I run the command gulp:

  1. It doesn't compile JS components to a main JS file.
  2. It compiles SCSS but when i save any file, the git-bash terminal executing files infinitely, here is the screenshot:
    enter image
description here

Here is my gulpfile.js:

"use strict";

const source = 'assets/';

// Load Modules
const { src, dest, watch, series } = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const postcss = require('gulp-postcss');
const cssnano = require('cssnano');
const terser = require('gulp-terser');
const browsersync = require('browser-sync').create();

// Scss Task
function scssTask() {
    return src(`${source}/scss/zaincss.scss`)
    .pipe(sass())
    .pipe(postcss([cssnano()]))
    .pipe(dest(`${source}/css`));
}

// Javascript Task
function jsTask() {
    return src(`${source}/js/scripts/*.js`)
    .pipe(terser())
    .pipe(dest(`${source}/js/scripts/`));
}

// BrowserSync Tasks
function browserSyncServe(done) {
    browsersync.init({
        server: {
            baseDir: '.'
        },
        injectChanges: true
    });
    done()
}

function browserSyncReload(done) {
    browsersync.reload();
    done();
}

// Watch Task
function watchTask() {
    watch('*.html', browserSyncReload);
    watch(['assets/scss/**/*.scss', 'assets/js/**/*.js'], series(scssTask, jsTask, browserSyncReload));
}

// Default Gulp Task
exports.default = series(
    scssTask, jsTask, browserSyncServe, watchTask
);

I have googled a lot, but i am stuck. Please help me.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Part of the problem is you are watching the same directory that you are storing your js files in:

// Javascript Task
function jsTask() {
    return src(`${source}/js/scripts/*.js`)
    .pipe(terser())
    .pipe(dest(`${source}/js/scripts/`));
}

So you send the files to ${source}/js/scripts/ but you are watching that location in your watch task: 'assets/js/**/*.js'. So any change in that location starts the process all over again.

Store you minified js files someplace else than the same directory you are watching for changes.

about 4 years ago · Juan Pablo Isaza Relatório
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