so have gulp file below.
the 'watch' block seems work absolutely fine, , expected. nodemon works in way detects file changes , refreshes server, works too.
but can't life of me nodemon call 'watch' method when file changes.
on line 81, .on('start' called succesfully nodemon, code inside 'watch' method never executed.
var gulp = require('gulp'); var gutil = require('gulp-util'); // logging stats , warnings var jshint = require('gulp-jshint'); // checking javascript warnings var concat = require('gulp-concat'); // joining multiple files var uglify = require('gulp-uglify'); // minimising files var coffee = require('gulp-coffee'); // compiling coffee script js var coflint = require('gulp-coffeelint');// checking coffee script errors var less = require('gulp-less'); // compiling less css var csslint = require('gulp-csslint'); // checking awesomeness of css var mincss = require('gulp-minify-css');// minifying css var uncss = require('gulp-uncss'); // deleting unused css rules var footer = require('gulp-footer'); // adding footer text files var nodemon = require('gulp-nodemon'); // super cool instant refreshing server var bsync = require('browser-sync'); // syncs place between multiple browsers dev var es = require('event-stream'); // working streams rather temp dirs var sourcepath = "sources"; var destpath = "public"; var jsfilename = "all.min.js"; var cssfilename = "all.min.css"; var footertext = ""; /* javascript tasks */ gulp.task('scripts', function(){ var jssrcpath = sourcepath + '/javascript/**/*'; var jsrespath = destpath + '/javascript'; var jsfromcs = gulp.src(jssrcpath+'.coffee')// coffee script .pipe(coflint()) // check cs errors or warnings .pipe(coflint.reporter()) // output error results .pipe(coffee()); // convert coffee vanilla js var jsfromplain = gulp.src(jssrcpath+'.js');// vanilla javascript return es.merge(jsfromcs, jsfromplain) // both js cs , vanilla js .pipe(jshint()) // check js errors or warnings .pipe(jshint.reporter('jshint-stylish')) // print js errors or warnings .pipe(concat(jsfilename,{newline: ';'})) // concatenate files .pipe(uglify()) // minify javascript .pipe(footer(footertext)) // add footer script .pipe(gulp.dest(jsrespath)); // save destination }); /* css tasks */ gulp.task('styles', function(){ var csssrcpath = sourcepath + '/styles/**/*'; var cssrespath = destpath + '/stylesheet'; var cssfromless = gulp.src(csssrcpath+'.less') // less code .pipe(less()); // convert less css var cssfromvanilla = gulp.src(csssrcpath+'.css');// css return es.merge(cssfromless, cssfromvanilla) // combine both css .pipe(csslint()) // check css errors or warnings .pipe(csslint.reporter()) // , output results .pipe(concat(cssfilename)) // concatenate files .pipe(mincss({compatibility: 'ie8'})) // minify css .pipe(gulp.dest(cssrespath)); // save destination }); /* configure files watch changes */ gulp.task('watch', function() { gulp.watch(sourcepath+'/**/*.{js,coffee}', ['scripts']); gulp.watch(sourcepath+'/**/*.{css,less}', ['styles']); }); /* start nodemon */ gulp.task('demon', function () { nodemon({ script: './bin/www', ext: 'js coffee css less html', env: { 'node_env': 'development'} }) .on('start', ['watch'])//todo: error: watch never called, though start called .on('change', ['watch']) .on('restart', function () { console.log('restarted!'); }); }); /* default task */ gulp.task('default', ['demon']); any suggestions why may happening? there wrong gulp file?
thanks in advance
(and yes, know code little over-commented, work apprentices , english better code ;)
the problem nodemon , browser-sync both need running. code works:
gulp.task('nodemon', function (cb) { var called = false; return nodemon({ script: './bin/www', watch: ['source/**/*'] }) .on('start', function onstart() { if (!called) { cb(); } called = true; }) .on('restart', function onrestart() { settimeout(function reload() { bsync.reload({ stream: false }); }, 500); }); }); gulp.task('browser-sync', ['nodemon', 'scripts', 'styles'], function () { bsync.init({ files: ['sources/**/*.*'], proxy: 'http://localhost:3000', port: 4000, browser: ['google chrome'] }); gulp.watch(sourcepath+'/**/*.{js,coffee}', ['scripts']); gulp.watch(sourcepath+'/**/*.{css,less}', ['styles']); gulp.watch("sources/**/*").on('change', bsync.reload); gulp.watch("views/**/*.jade").on('change', bsync.reload); }); /* default task */ gulp.task('default', ['clean', 'browser-sync']);
Comments
Post a Comment