A
A
Andrej Sharapov2019-07-04 14:42:04
JavaScript
Andrej Sharapov, 2019-07-04 14:42:04

How to connect gulp-watch?

Good afternoon!
Can you tell me how to properly connect and start tracking for css & js files?
tasks:

const watch = require('gulp-watch');

 gulp.task('cssc', () => {
    return gulp.src('./build/scss/*.css')
        .pipe(sourcemaps.init())
        .pipe(csscomb())
        .pipe(mmq({
            log: true
        }))
        .pipe(cleanCSS())
        .pipe(rename({
            suffix: ".min"
        }))
        .pipe(sourcemaps.write())
        .pipe(gulp.dest('./css/'))
});

gulp.task('jsc', () => {
    return gulp.src(['bodyload.js', 'toggle.js'].map(file => `./build/js/${file}`))
        .pipe(sourcemaps.init())
        .pipe(babel({
            presets: ['@babel/preset-env']
        }))
        .pipe(concat('scripts.js'))
        .pipe(uglify())
        .pipe(rename("scripts.min.js"))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest('./js/'))
});

gulp.task('watch', function() {
    gulp.watch('./build/scss/*.css', ['cssc']);
    gulp.watch('./build/js/*.js', ['jsc']);
  });

does not work

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
A person from Kazakhstan, 2019-07-04
@Madeas

https://www.youtube.com/watch?v=r2S423N-ETA I didn’t see this lesson better on youtube at all

V
Vladimir Skibin, 2019-07-04
@megafax

Make a task
clean - cleaned build, build - collected, watch - put on observation

R
Rag'n' Code Man, 2019-07-06
@iDmitriyWinX

Hello, most likely you are using the 4th gulp, where the task call is implemented differently.
Instead of an array, a function is passed as the second argument, either gulp.series or gulp.parralel. In arguments, you pass the names of tasks without any arrays (gulp.series("task", "task")).
PS Put semicolons after the last pipes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question