I am currently running a local server using WAMP and I am trying to set up Gulp.js. Here are the contents of my gulpfile:
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
minifyhtml = require('gulp-minify-html'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
rename = require('gulp-rename'),
clean = require('gulp-clean'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
cache = require('gulp-cache'),
livereload = require('gulp-livereload'),
lr = require('tiny-lr'),
server = lr();
gulp.task('styles', function() {
gulp.src('src/styles/main.scss')
.pipe(sass({ style: 'expanded' }))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(gulp.dest('dist/assets/css'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest('dist/css'))
.pipe(livereload(server))
.pipe(notify({ message: 'Styles task complete' }));
});
gulp.task('html', function() {
gulp.src('src/*.php')
.pipe(minifyhtml())
.pipe(gulp.dest('dist'))
.pipe(livereload(server))
.pipe(notify({ message: 'HTML task complete' }));
});
gulp.task('default', function() {
gulp.run('html');
});
And here is the output I am getting when I run gulp:
[gulp] Using gulpfile C:\wamp\www\SawyerK\gulpfile.js
[gulp] Starting 'default'...
gulp.run() has been deprecated. Use task dependencies or gulp.watch task trigger
ing instead.
[gulp] Starting 'html'...
[gulp] Finished 'html' after 132 ms
[gulp] Finished 'default' after 134 ms
[gulp] gulp-notify: [Gulp notification] HTML task complete
events.js:72
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED
at errnoException (net.js:904:11)
at Object.afterConnect [as oncomplete] (net.js:895:19)
From what I have found, this error is thrown because something else is using the port Node wants or something like that? However, I am not completely sure if that's right and I definitely don't have a clue how to fix it. Any thoughts? Thanks!
Edit: I seem to have it narrowed down to gulp-notify if that helps
I think the problem is that you use livereload twice, in styles task and html. Maybe it's better use livereload with watcher:
gulp.task('watch', function() {
var server = livereload();
gulp.watch('build/**').on('change', function(file) {
server.changed(file.path);
});
});
update: Sorry, was wrong =) Here is a great article, and second part that shows how to use watch task. link To work with livereload you need to start the server with listen method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With