0
votes

so i started yesterday with gulp 4.0 so when i start gulp he only compile my sass to css in the first run. idk why this is my


const { src, dest, watch, series, parallel } = require('gulp');
const sass = require('gulp-sass');
const postcss = require('gulp-postcss');
const cssnano = require('cssnano');
const sourcemaps = require('gulp-sourcemaps');
const autoprefixer = require('autoprefixer');


// File paths
const files = { 
    scssPath: '/scss/*.scss',
    cssPath: '/css/'
}


function scssTask(){    
    return src(files.scssPath)
        .pipe(sourcemaps.init()) 
        .pipe(sass()) 
        .pipe(postcss([ autoprefixer(), cssnano() ]))  
        .pipe(sourcemaps.write('.')) 
        .pipe(dest(files.cssPath)
    ); 
}



function watchTask(){
    watch([files.scssPath], 
        scssTask
        );  
}

exports.default = series(
    scssTask,
    watchTask
);

LOGS; [22:36:57] Using gulpfile D:\xampp\htdocs\project\gulpfile.js

[22:36:57] Starting 'default'...

[22:36:57] Starting 'scssTask'...

[22:36:57] Finished 'scssTask' after 13 ms

[22:36:57] Starting 'watchTask'...

1

1 Answers

0
votes

I would assume that what you want is really:

const files = { 
    scssPath: './scss/*.scss',
    cssPath: './css/'
}

Note the . added to the start of each value. To make them relative to the location of the gulpfile.js.