Y
Y
Yevhenii K2019-08-03 19:01:55
JavaScript
Yevhenii K, 2019-08-03 19:01:55

Why does this gulpfile not work correctly?

The problem is that after running watch for scss files, it only works when the file is changed for the first time, for html it just doesn’t work, it starts bound and nothing happens. Why is this happening and how to fix it?

[Browsersync] Access URLs:
--------------------------------------
      Local: http://localhost:8000
    External: http://192.168.1.149:8000
--------------------------------------
          UI: http://localhost:3001
UI External: http://localhost:3001
--------------------------------------
[Browsersync] Serving files from: dist
[18:35:30] Starting 'sassCompilation'...
[Browsersync] 1 file changed (style.css)
[18:35:30] Finished 'sassCompilation' after 33 ms
[18:35:30] Starting 'browserSyncReload'...
[Browsersync] Reloading Browsers...
[18:35:39] Starting 'bound '...

"use strict";

const {
    series,
    parallel,
    src,
    dest,
    watch
} = require('gulp');
const bs = require('browser-sync').create();
const sass = require('gulp-sass');
const panini = require('panini');
const rimraf = require('rimraf');

function server() {
    bs.init({
        server: {
            baseDir: "dist",
        },
        port: 8000
    });
}

function sassCompilation() {
    return src('src/assets/scss/style.scss')
        .pipe(sass().on('error', sass.logError))
        .pipe(dest('dist/css'))
        .pipe(bs.stream());
}

function html() {
    return src('src/pages/*.html')
        .pipe(panini({
            root: 'src/pages/',
            layouts: 'src/layouts/',
            partials: 'src/partials/',
            data: 'src/data/',
            helpers: 'src/helpers/'
        }))
        .pipe(dest('dist/'));
}

function clean(done) {
    rimraf('dist', done);
}


exports.default = series(
    clean,
    sassCompilation,
    html,
    parallel(server, function () {
        watch('src/assets/scss/**/*', series(sassCompilation, bs.reload));
        watch('src/{layouts,partials,pages,helpers,data}/**/*', series(panini.refresh, html, bs.reload));
}));

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question