I recently recognized gulp and wrote this gulp script on my local computer so that it could follow any changes and compile my javascripts (in this case ./js/main.jswith its dependencies) into a single file ./js/bundle.js:
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var browserify = require('gulp-browserify');
var rename = require('gulp-rename');
gulp.task('lint', function() {
return gulp.src(['./js/**/*.js', '!./js/bundle.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('b', function() {
gulp.src('js/main.js')
.pipe(browserify())
.pipe(rename('bundle.js'))
.pipe(gulp.dest('js/'));
});
gulp.task('watch', function() {
gulp.watch(['./js/*.js', './js/**/*.js', '!./js/bundle.js'], ['lint', 'b'])
.on('change', function(event) {
console.log("\n============");
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});
});
gulp.task('default', ['lint', 'watch']);
It works well on my local computer (Windows 7), so I tried putting it on my remote Ubuntu server and letting it keep track of any ftp updates and scroll through them.
In other words, I want to remotely encode and update ./js/main.jsvia ftp and have gulp keep track of the changes and scroll it automatically.
The problem is this: gulp recognizes the changes and logs into the console:
File /home/wordpress/public_html/cm/mobileCoder02/src/js/main.js was changed, running tasks...
[09:27:47] Starting 'lint'...
[09:27:47] Starting 'b'...
[09:27:47] Finished 'b' after 34 μs
[09:27:47] Finished 'lint' after 6.71 ms
But the output file bundle.jscontains nothing but a script module loader:
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
},{}]},{},[1])
gulp.task('b', function() {
setTimeout(function() {
gulp.src('js/main.js')
.pipe(browserify())
.pipe(rename('bundle.js'))
.pipe(gulp.dest('js/'));
}, 1000);
});
.
, , . gulp.watch() "change" ftp? , , , ?
.