javascript - Can't get gulp watch to trigger build function on file change within supposedly watched folder -


i've tried couple of ways gulp watch folder of files in order rebuild on file change , stop me having manually.

i'm sure in grunt worked adding watch task array of build tasks , finish initial build leaving watch open listen changes during development session.

i've tried this, taken this example gulp readme - i've removed batch call want build trigger on every event.

gulp.task('watch', function () {     watch('src/**/*.js', function (events, done) {         gulp.start('build', done);     }); }); 

the call gulp watch works , appears watching, error displayed make change file in folder.

my build function works - i've been not happily triggering manually far!

/users/tonileigh/node_modules/gulp/node_modules/orchestrator/index.js:89                     throw new error('pass strings or arrays of strings');                           ^ error: pass strings or arrays of strings     @ gulp.orchestrator.start (/users/tonileigh/node_modules/gulp/node_modules/orchestrator/index.js:89:12)     @ /users/tonileigh/development/shadowcat/gulpfile.js:26:14     @ write (/users/tonileigh/node_modules/gulp-watch/index.js:123:9)     @ /users/tonileigh/node_modules/gulp-watch/node_modules/vinyl-file/index.js:52:4     @ /users/tonileigh/node_modules/gulp-watch/node_modules/vinyl-file/node_modules/graceful-fs/graceful-fs.js:76:16     @ fs.js:334:14     @ /users/tonileigh/node_modules/gulp-watch/node_modules/vinyl-file/node_modules/graceful-fs/graceful-fs.js:42:10     @ /users/tonileigh/node_modules/gulp-watch/node_modules/chokidar/node_modules/readdirp/node_modules/graceful-fs/graceful-fs.js:42:10     @ fsreqwrap.oncomplete (fs.js:95:15) 

i've tried this, based on this example gulp readme:

jsxtojs = function() {   gulp.src('src/**/*.js')     .pipe(watch('src/**/*.js'))     .pipe(react())     .pipe(concat('javascript.js'))     .pipe(gulp.dest('./')); } 

i'm mistaken, i'm expecting watch glob changes , apply function. function takes jsx , converts raw js reactjs concats files finds single js file.

it doesn't error, new directory in root follows pattern in glob, creating new compiled example of saved file

my full file, without 2 above attempts, here:

var gulp = require('gulp'),     concat = require('gulp-concat'),     react = require('gulp-react'),     sass = require('gulp-sass'),     watch = require('gulp-watch'),      jsxtojs = function() {       gulp.src('src/**/*.js')         .pipe(react())         .pipe(concat('javascript.js'))         .pipe(gulp.dest('./'));     },      scsstocss = function() {       gulp.src('src/style.scss')         .pipe(sass('style.css').on('error', sass.logerror))         .pipe(gulp.dest('./'));     };  gulp.task('jsxtojs', jsxtojs); gulp.task('styles', scsstocss); gulp.task('js', ['jsxtojs', 'concat']); gulp.task('build', ['jsxtojs', 'styles']); 

  1. try find yeoman generators gulp , install them
  2. use code
    gulp = require('gulp);     var $ = require('gulp-load-plugins')();     var browsersync = require('browser-sync);     var reload = browsersync.reload;      gulp.task('mysupertask', function () {         gulp.watch('src/**/*.js').on('change', reload);     }); 

this reload each time make changes js. can make build task , add script this:

... gulp.task('mybuildtask, function() {     gulp.src('src/**/*.coffee')     .pipe($.coffee())     .pipe($.uglify())     .pipe(gulp.dest('src/scripts')); });  gulp.task('mysupertask', function () {     gulp.watch('src/**/*.js').on('change', ['mybuildtask'],reload); }); 

and can run gulp mysupertask

not sure mybuildtask string syntax


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -