Answer the question
In order to leave comments, you need to log in
How to write a task correctly?
There are 3 tasks for sass, js and watch
The task is to make a default task for Gulp 4, so that when it starts, css, js files are immediately formed, and then watch and browser sync are launched.
PS If you write as shown below, then at startup and further changes in sass or js files, the corresponding tasks will be performed twice, but this is not necessary.
gulp.task('default', gulp.series(
gulp.parallel('styles', 'scripts', 'images'),
gulp.parallel('watch', 'browser-sync')
));
gulp.task('styles', function(){
return gulp.src(source+'/'+syntax+'/**/*.'+syntax)
.pipe(sass({ outputStyle: 'expanded' }).on("error", notify.onError()))
.pipe(autoprefixer(['last 15 versions']))
.pipe(cleancss({ level: { 1: { specialComments: 'all' } } }))
.pipe(rename({ prefix: '', suffix: '.min' }))
.pipe(gulp.dest(source+'/css'))
.pipe(browserSync.stream())
});
gulp.task('scripts', function() {
return gulp.src(source+'/js/**/*.js')
.pipe(concat('scripts.js'))
.pipe(uglify())
.pipe(rename({prefix: '', suffix: '.min'}))
.pipe(gulp.dest(source+'/js'))
.pipe(browserSync.stream())
});
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: source
},
notify: false,
})
});
gulp.task('watch', function() {
gulp.watch(source+'/*.html')
gulp.watch(source+'/'+syntax+'/**/*.'+syntax)
gulp.watch(source+'/js/common.js')
});
Answer the question
In order to leave comments, you need to log in
Something about galp 4 has become a lot of questions, do not use the new version right away, wait for a while until the docks and uses cases appear, then just move on.
Maybe my example will help:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question