A
A
Azat S.2015-09-08 19:32:45
gulp.js
Azat S., 2015-09-08 19:32:45

Gulp.run() is deprecated. How to fix the error?

Hello!
After adding the gulp-watch plugin, gulp-connect stopped working with livereload. Here is a part of my gulpfile.js:

var connect = require('gulp-connect');
var gulp = require('gulp');
var livereload = require('gulp-livereload');
var watch = require('gulp-watch');

gulp.task('default', function() {
  gulp.run('server');
  gulp.watch('src/jade/**', function(event) {
    gulp.run('jade');
  });
  gulp.watch('src/css/**', function(event) {
    gulp.run('postcss');
  });
  gulp.watch('src/images/**/*', batch(function (events, done) {
      gulp.start('images', done);
  }));
});

// Server

gulp.task('server', function() {
  connect.server({
    root: 'dist',
    livereload: true
  });
});

Gives the following error:
[email protected]:~/git/lasttest$ gulp
[19:30:48] Using gulpfile ~/git/lasttest/gulpfile.js
[19:30:48] Starting 'default'...
gulp.run() has been deprecated. Use task dependencies or gulp.watch task triggering instead.
[19:30:48] Starting 'server'...
[19:30:48] Finished 'server' after 9.36 ms
[19:30:48] Finished 'default' after 32 ms
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: listen EADDRINUSE
    at exports._errnoException (util.js:746:11)
    at Server._listen2 (net.js:1156:14)
    at listen (net.js:1182:10)
    at Server.listen (net.js:1267:5)
    at ConnectApp.server (/home/azat/git/lasttest/node_modules/gulp-connect/index.js:57:19)
    at new ConnectApp (/home/azat/git/lasttest/node_modules/gulp-connect/index.js:37:10)
    at Object.module.exports.server (/home/azat/git/lasttest/node_modules/gulp-connect/index.js:170:12)
    at Gulp.<anonymous> (/home/azat/git/lasttest/gulpfile.js:112:11)
    at module.exports (/home/azat/git/lasttest/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/home/azat/git/lasttest/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
[email protected]:~/git/lasttest$

Tell me the best way to fix it? It is necessary that when gulp is launched, a server is created at localhost:8080 and updated in case of any changes. The above code worked before.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Yarosh, 2015-09-08
@azat-io

gulp.task('default', ['server'], function() {
  gulp.watch('src/jade/**', ['jade']);
  gulp.watch('src/css/**', ['postcss']);
  gulp.watch('src/images/**/*[email protected](png|jpg)', ['images']);
});

For livereload, it's better to use browsersync .
It is important not to forget to return streams and call callbacks so that synchronization would normally occur .
Gotta do it like this
gulp.task('js',function(){
    return gulp.src('./assets/js/*.js')
        .pipe(doSomeStuff());
});

and like this
var merge = require('merge-stream');

gulp.task('js',function(){
    merged = merge();
    [
      'mdpi', 'hdpi', 'xhdpi'
    ].forEach(function(density) {
    merged.add(gulp.src('app/images/**/*[email protected](png|gif|jpeg)')
        .pipe(doSomeMagicStuff()))
        .pipe(gulp.dest('dist/images/' + density)));
    });

    return merged;
});

if you need to process several files at the same time.
Well, you can use callbacks
var plato = require('plato');

gulp.task('plato', function(done) {
    plato.inspect('app/**/*.js', 'reports', {}, function(reports) {
        done();
    });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question