Good day!

Tell me why Gulp only updates coffee at startup, nothing happens when you change coffee files.

gulpfile.js:

var gulp = require('gulp'), jade = require('gulp-jade'), stylus = require('gulp-stylus'), coffee = require('gulp-coffee'), livereload = require('gulp-livereload'), imagemin = require('gulp-imagemin'), concat = require('gulp-concat'), connect = require('connect'), serveStatic = require('serve-static'), nib = require('nib'); /* * Создаём задачи * * stylus – для CSS-препроцессора Stylus * jade – для HTML-препроцессора Jade * coffee – для JavaScript-препроцессора CoffeеScript * concat – для склейки всех CSS и JS в отдельные файлы */ gulp.task('stylus', function() { gulp.src('./styl/*.styl') .pipe(stylus({use: nib(), compress: true})) .on('error', console.log) // Выводим ошибки в консоль .pipe(gulp.dest('./public/css/')) // Выводим сгенерированные CSS-файлы в ту же папку по тем же именем, но с другим расширением .pipe(livereload()); // Перезапускаем сервер LiveReload }); gulp.task('jade', function(){ gulp.src('./*.jade') .pipe(jade({pretty: true})) .on('error', console.log) // Выводим ошибки в консоль .pipe(gulp.dest('./public/')) // Выводим сгенерированные HTML-файлы в ту же папку по тем же именем, но с другим расширением .pipe(livereload()); // Перезапускаем сервер LiveReload }); gulp.task('coffee',function(){ gulp.src('./coffee/*.coffee') .pipe(coffee({bare: true})) .on('error', console.log) // Выводим ошибки в консоль .pipe(gulp.dest('./public/js')) // Выводим сгенерированные JavaScript-файлы в ту же папку по тем же именем, но с другим расширением .pipe(livereload()); // Перезапускаем сервер LiveReload }); gulp.task('concat', function(){ gulp.task('coffee'); gulp.src('./public/js/*.js') .pipe(concat('scripts.js')) .pipe(gulp.dest('./public/min/')) .pipe(livereload()); gulp.task('styl'); gulp.src('./public/css/*.css') .pipe(concat('styles.css')) .pipe(gulp.dest('./public/min/')) .pipe(livereload()); }); gulp.task('imagemin',function(){ gulp.src('./img/**/*') .pipe(imagemin()) .pipe(gulp.dest('./public/img/')); }); /* * Создадим веб-сервер, чтобы работать с проектом через браузер */ gulp.task('server', function() { connect() .use(require('connect-livereload')()) .use(serveStatic(__dirname + '/public')) .listen('3333'); console.log('Сервер работает по адресу http://localhost:3333'); }); /* * Создадим задачу, смотрящую за изменениями */ gulp.task('watch', function(){ livereload.listen(); gulp.watch('./styl/*.styl',['stylus']); gulp.watch('./*.jade',['jade']); gulp.watch('./coffee/*.coffee',['coffee']); gulp.watch(['./public/js/*.js','./public/css/*.css'],['concat']); gulp.watch('./img/**/*',['imagemin']); gulp.start('server'); }); gulp.task('default',['watch','stylus','jade','coffee','concat','imagemin']); 
  • From your question it is not clear which command you are running. I would say that you need to run gulp watch - Mikhail Chibel
  • I run the watch command in Gulp in default. - VINET
  • Maybe the assembly is just falling yesterday. - Vladimir Gamalyan
  • styl and jade works - VINET
  • Give me a photo of your project structure. - VostokSisters

1 answer 1

Using gulp-watch solves the problem:

 var gulp = require('gulp'), watch = require('gulp-watch'); // Watcher gulp.task('watch', function() { watch('./views/**/*', function() { gulp.start('views') }); watch('./styl/**/*', function() { gulp.start(['css', 'views']) }); watch('./js/**/*', function() { gulp.start(['js', 'js-embded']) }); watch('./js/contact.js', function() { gulp.start('browserify') }); watch('./img/**/*', function() { gulp.start(['imagemin', 'webp']) }); watch('./img/favicons/**/*', function() { gulp.start('favicons') }); watch('./fonts/**/*', function() { gulp.start(['iconfont', 'fonts']) }); watch('./seo/**/*', function() { gulp.start('seo') }); }); 
  • or you can go to gulp-4, it has a normal watcher. - DimenSi
  • @DimenSi and where do you see Gulp 4? mine is the latest version 3.9.1 - user232857
  • @DimenSi is not a release. Alpha only. - user232857
  • So what? He was in the alpha version was stable, and now he removed the prefix. - DimenSi