• Почему gulp.watch используется только 1 раз?

    potapchino
    @potapchino
    function compileJade(done) {
      gulp.src('src/jade/*.jade')
        .pipe(plumber())
        .pipe(jade())
        .pipe(gulp.dest('build/'))
        .pipe(server.reload({ stream: true }));
      
      
      done()
    }
    
    function compileScss(done) {
      gulp.src([
        'src/sass/*.scss',
        '!src/sass/mixins.scss',
        '!src/sass/normalize.scss',
        '!src/sass/variable.scss'
      ])
        .pipe(plumber())
        .pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
        .pipe(postcss([
          autoprefixer({
            browsers: [
              "last 1 version",
              "last 2 Chrome versions",
              "last 2 Firefox versions",
              "last 2 Opera versions",
              "last 2 Edge versions"
            ],
            grid: true
          })
        ]))
        .pipe(gcmq())
        .pipe(minify())
        .pipe(gulp.dest('build/css'))
        .pipe(server.reload({ stream: true }));
      
      
      done()
    }
    
    function compileScripts(done) {
      gulp.src('src/js/*.js')
        .pipe(plumber())
        .pipe(jsmin())
        .pipe(gulp.dest('build/js/'))
        .pipe(server.reload({ stream: true }));
      
      
      done()
    }
    
    function makeHash(done) {
      gulp.src('build/index.html')
        .pipe(hash())
        .pipe(gulp.dest('build'));
      
      
      done()
    }
    
    function watcher(done) {
      server.init({
        server: 'build'
      });
      
      gulp.watch('src/sass/**/*.scss', gulp.series(compileScss, makeHash));
      gulp.watch('src/**/*.jade', gulp.series(compileJade, makeHash));
      gulp.watch('src/js/*.js', gulp.series(compileScripts, makeHash));
      
      
      done()
    }
    
    module.exports = {
      default: watcher,
      watcher,
      build: gulp.series(
        compileJade,
        compileScss,
        compileScripts,
        makeHash
      ),
      jade: compileJade,
      style: compileScss,
      script: compileScripts,
      hash: makeHash
    }
    Ответ написан
    3 комментария