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

369
Views
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 answers
Answer question

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 Report
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!